kb_ota.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:68k
- /******************************************************************************
- *
- * FileName :kb_ota.c
- * FileDesc : This is the dtvia implementation file for mojo
- *
- ******************************************************************************/
- //-----------------------------------------------------------------------------
- // Standard include files:
- //-----------------------------------------------------------------------------
- //
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- //-----------------------------------------------------------------------------
- // Project include files:
- //-----------------------------------------------------------------------------
- //
- #include <stdlib.h>
- #include <stdio.h>
- #include "Gendef.h"
- #include "appltype.h"
- #include "osp.h"
- #include "sti5105.h"
- #include "Dmd.h"
- #include "Dmx.h"
- #include "Timer.h"
- #include "db.h"
- #include "Eprom.h"
- #include "Timer.h"
- #include "kb_ota.h"
- #include "osd.h"
- #include "kb_porting.h"
- #include "kb_machblue_client_lc.h"
- #include "kb_machblue_client.h"
- //-----------------------------------------------------------------------------
- // Types and defines:
- //-----------------------------------------------------------------------------
- //
- static UInt32 _unused;
- #define UNUSED_PARAMETER2(x) _unused = (UInt32)(x);
- //priority and stack size of CA Client task
- #define OTA_CLIENT_PRIORITY (1*16)
- #define OTA_CLIENT_STACK_SIZE (2 * 1024)
- //queue size and packet size of CA Client Queue
- #define OTA_CLIENT_QUEUE_SIZE 64
- #define OTA_CLIENT_PACKET_SIZE (sizeof(stCAClientMsg))
- //-----------------------------------------------------------------------------
- // Global data:
- //-----------------------------------------------------------------------------
- //
- typedef enum
- {
- L_SCT_PAT = 0,
- L_SCT_CAT,
- L_SCT_PMT,
- L_SCT_LPMT,
- L_SCT_SDT,
- L_SCT_BAT,
- L_SCT_NIT,
- L_SCT_DII,
- L_SCT_DSI,
- L_SCT_CTRL,
- L_SCT_TDT,
- L_SCT_DUMMY
- }CaClientFilterEnum;
- static TaskHandle_t _hTask;
- static QueueHandle_t _hQueue;
- QueueHandle_t _OtaQueue;
- static Timer_Handle_t _lDownloadTimer = 0xffffffff;
- static Int32 _TimerCount;
- static Bool _TimerFlag;
-
- static UCHAR _uSectionHardMask[8];
- static UCHAR _uSectionHardValue[8];
- static UInt8 _bakBatSection[4 * 1024]; //For Bug101
- static UInt8 _bakPatSection[4*1024], _bakdlPmtSection[4*1024];
- static UInt8 _shareNitSection[4 * 1024], _bakNitSection[4 * 1024];
- static UInt8 _bakDSISection[4 * 1024];
- static TF_Linkage_Descriptor _astTFLinkage[MAX_IRDETO_LINKAGES];
- static UInt32 _lTFLinkageNum;
- static TF_Linkage_Descriptor * _pManuDlLinkage = NULL;
- static Bool _bCurrentNitValid, _bCurrentBatValid = False; //For Bug101
- static BOOL _flag_Download_Allowed;
- static UInt32 _dlFreq, _dlSymb, _dlQam;
- static UInt32 _dlPid;
- static Bool _bDownloadChecking = False;
- static Bool _bDownloadComparing = False;
- static Bool _bPmtFirst = True;
- static Bool _bOnlyStopTimer = False;
- unsigned short _Error_Code = 255;
- //暂时使用
- UInt32 DmuxDrvDebugMsgLvl = 0x000;
- //loader参数
- TFLoaderPara gKBloaderPara;
- Bool _bDownloadTrigger = False;
- static BOOL updateLock=True;
- UInt8 OTAParabuf[68];
- Int8 SectionCounter = 0;
- static BOOL updatePrevent=FALSE;
- static BOOL updateMainPrevent=FALSE;
- static BOOL OTAOsdRun =FALSE;
- static BOOL OTAManuEnable =FALSE;
- int g_menu_ota = FALSE;
- static BOOL gUpdateSearch=FALSE;
- int playlock=0;
- Ota_Hint_Message ota_message;
- //-----------------------------------------------------------------------------
- // Internal Function Prototypes:
- //-----------------------------------------------------------------------------
- //
- static StbErr_t PsiFilterSetup( DMX_FilterID lFilterId, UInt16 lPid,
- UInt16 lTableId, UInt16 lTableIdExt,
- UInt16 lVersion, UInt16 lSectionNumber, CaClientFilterEnum Num);
- StbErr_t KB_PsiFilter_Setup(DMX_FilterID lFilterId, UInt16 lPid,
- UInt16 lTableId, UInt16 lTableIdExt,
- UInt16 lVersion, UInt16 lSectionNumber, CaClientFilterEnum Num);
- void CommonfilterCallback(UINT32 nChannelID, UINT8 *pData, UINT32 nDataLength);
- static void OTAClientTask(void * dummy);
- TFLoaderPara * ReadHLLoaderParams(void);
- Bool OTA_CLIENT_GetDLTuneParams(UInt32 * olFreq, UInt32 * olSymb, UInt32 * olModulate);
- static int GetDLTuneParams(void);
- int KB_BeginDownloadSearching(void);
- static void DownloadTimerCallback (void);
- void KB_ErrorMsg(UInt16 code);
- void WriteHLLoaderParams(void);
- static UInt16 ExtractDLPidFromPMT(void);
- static UInt16 ExtractDlPmtPidFromPat(void);
- static void FePara(UInt32 SaveLoad);
- static int StbStreamPara_Compare(unsigned short pid);
- void KB_UpdateCheckClear(void);
- static void ExtraceTFLinkage(void);
- static void ExtractManuDlLinkageEx(void);
- int GetUpgradeType(TF_Linkage_Descriptor * pManuDlLinkage);
- unsigned char OTA_CLIENT_GetDownloadState(void);
- INT32 KB_DCFilter_Service(unsigned short pid);
- void MSG_RemainTimeDisplay(Int32 second, Bool flag);
- void KB_Flash_lc_MSGBox_Close(void);
- //-----------------------------------------------------------------------------
- // 函数实体
- //-----------------------------------------------------------------------------
- //
- //手动设置开关
- void KB_OTAManuEnableSet(BOOL flag)
- {
- OTAManuEnable = flag;
- return;
- }
- BOOL KB_OTAManuEnableGet()
- {
- return OTAManuEnable;
- }
- //空中升级开关
- void KB_UpdatePreventSet(BOOL flag)
- {
- updatePrevent = flag;
- return;
- }
- BOOL KB_UpdatePreventGet()
- {
- printf("n KB_UpdatePreventGet=%d",updatePrevent );
- return updatePrevent;
- }
- void KB_UpdateMainPreventSet(BOOL flag)
- {
- updateMainPrevent = flag;
- return;
- }
- BOOL KB_UpdateMainPreventGet()
- {
- return updateMainPrevent;
- }
- void KB_OTARunSet(BOOL flag)
- {
- OTAOsdRun = flag;
- return;
- }
- BOOL KB_OTARunGet()
- {
- return OTAOsdRun;
- }
- /*************************************************************************************
- GetUpdateSearchStatus
- Description: get Updating status
- Input: dummy - unused parameter
- Output: None
- Return: None
- *************************************************************************************/
- BOOL GetUpdateSearchStatus()
- {
- return gUpdateSearch;
- }
- /*************************************************************************************
- setUpdateSearchStatus
- Description: set Updating status
- Input: dummy - unused parameter
- Output: None
- Return: None
- *************************************************************************************/
- void SetUpdateSearchStatus(BOOL flag)
- {
- gUpdateSearch = flag;
- }
- void Set_DownloadChecking(BOOL flag)
- {
- _bDownloadChecking = flag;
- }
- BOOL Get_DownloadChecking(void)
- {
- return _bDownloadChecking;
- }
- void LockPlayPgm()
- {
- playlock = 1;
- }
- /*************************************************************************************
- UnLockPlayPgm
- Description:打开视频播放锁
- Input: dummy -
- Output: None
- Return: None
- *************************************************************************************/
- void UnLockPlayPgm(void)
- {
- playlock = 0;
- }
- /*************************************************************************************
- GetLockPlayPgm
- Description: 关闭视频播放锁
- Input: dummy -
- Output: None
- Return: None
- *************************************************************************************/
- int GetLockPlayPgm(void)
- {
- return playlock;
- }
- /*************************************************************************************
- Ota_test2
- Description: test only
- Input: dummy -
- Output: None
- Return: None
- *************************************************************************************/
- void Ota_test2(void)
- {
- KB_OTAManuEnableSet(False);
- }
- int Kb_dmux_init(void)
- {
- INT32 nReturn;
- #define FILTER_DEPTH (8)
- nReturn = KB_DmxAllocateChnnl(DMX_CHANNEL_SECTION, 5 * 1024, TRUE, &channelID);
- if(nReturn != 0)
- {
- printf("KD_DmxAllocateChnnl fail = %ldn",nReturn);
- return -1;
- }
- KB_DmxRegNotice(channelID, CommonfilterCallback);
- nReturn = KB_DmxAllocateFilter(DMX_SECTION_FILTER, FILTER_DEPTH, &filterID);
- if(nReturn != 0)
- {
- printf("KD_DmxAllocateFilter fail = %ldn",nReturn);
- return -1;
- }
- printf("n channelID=%ld",channelID);
- printf("n filterID=%ld",filterID);
- nReturn = KB_DmxAssociateFilter(channelID, filterID);
- printf("n nReturn=%ld",nReturn);
- if(nReturn != 0)
- {
- printf("KD_DmxAssociateFilter fail = %ldn",nReturn);
- return -1;
- }
- return 0;
- }
- /*************************************************************************************
- OTA_CLIENT_Service
- Description: Send message to CA Client task for service
- **************************************************************************************/
- void OTA_CLIENT_Service (KB_OSPMsgNode *pMsg)
- {
- //printf("n OTA_CLIENT_Service:Word1=%ld Word2=%ld", pMsg->Word1, pMsg->Word2);
- KB_OSPMsgSend(_hQueue, pMsg);
- }
- /*************************************************************************************
- OTA_lc_Service
- Description: Send message to CA Client task for service
- **************************************************************************************/
- void OTA_lc_Service (KB_OSPMsgNode *pMsg)
- {
- printf("n OTA_lc_Service:Word1=%ld", pMsg->Word1);
- KB_OSPMsgSend(_OtaQueue, pMsg);
- }
- Int8 KB_PsiFilter_Stop(void)
- {
- KB_DmxControlChnnl(channelID, KB_DMX_STOP);
- SectionCounter--;
- //printf("n KB_PsiFilter_Stop return: %d", SectionCounter);
- return SectionCounter;
- }
- StbErr_t KB_PsiFilter_Setup(DMX_FilterID lFilterId, UInt16 lPid,
- UInt16 lTableId, UInt16 lTableIdExt,
- UInt16 lVersion, UInt16 lSectionNumber, CaClientFilterEnum Num)
- {
- StbErr_t Ret;
-
- Ret = PsiFilterSetup( lFilterId, lPid, lTableId, lTableIdExt, lVersion, lSectionNumber, Num);
- if(Ret != TM_OK)
- {
- Print("n[KB_PsiFilter_Setup]Error: set filter failed.n");
- SectionCounter=0;
- return Ret;
- }
- SectionCounter=1;
- return Ret;
- }
- /*************************************************************************************
- CommonFilterCallback
- Description: When cat, sdt or pmt reached, this function would be called.
- Input: tFilteriD - filter ID
- pstPacket - section data
- dummy * - dummy parameter
- Output: None
- Return: Always 0
- *************************************************************************************/
- void CommonfilterCallback(UINT32 nChannelID, UINT8 *pData, UINT32 nDataLength)
- {
- KB_OSPMsgNode MsgCaClient;
- Int8 res;
-
- if(pData == NULL)
- return;
- if(nDataLength > 1024)
- {
- Print("rn[CA_CLIENT]Section is too largern");
- while(1);
- }
- switch (pData[0]) //tableid
- {
- case 0x00: // PAT:
- Print("nCommonfilterCallback:pat recieved");
-
- res = KB_PsiFilter_Stop();
- if(res<0) break;
- memcpy(_bakPatSection, pData, nDataLength);
- MsgCaClient.Word1 = E_PAT_REACH;
- MsgCaClient.Word2 = nDataLength;
- OTA_CLIENT_Service (&MsgCaClient);
- break;
-
- case 0x02: // PMT
- Print("nCommonfilterCallback:pmt recieved");
-
- res = KB_PsiFilter_Stop();
- if(res<0) break;
- memcpy(_bakdlPmtSection, pData, nDataLength);
- MsgCaClient.Word1 = E_PMT_REACH;
- MsgCaClient.Word2 = nDataLength;
- OTA_CLIENT_Service (&MsgCaClient);
- break;
- case 0x4A: // BAT
- Print("nCommonfilterCallback:BAT recieved");
- res = KB_PsiFilter_Stop();
- if(res<0) break;
-
- memcpy(_bakBatSection, pData, nDataLength);
- MsgCaClient.Word1 = E_BAT_REACH;
- MsgCaClient.Word2 = nDataLength;
- OTA_CLIENT_Service (&MsgCaClient);
- break;
-
- case 0x40: // NIT
- Print("nCommonfilterCallback:NIT recieved");
-
- res = KB_PsiFilter_Stop();
- if(res<0) break;
- memcpy(_bakNitSection, pData, nDataLength);
- MsgCaClient.Word1 = E_NIT_REACH;
- MsgCaClient.Word2 = nDataLength;
- OTA_CLIENT_Service (&MsgCaClient);
- break;
- case 0x3b: // DII DSI
- Print("nCommonfilterCallback:DSI recieved");
- res = KB_PsiFilter_Stop();
- if(res<0) break;
- memcpy(_bakDSISection, pData, nDataLength);
- MsgCaClient.Word1 = E_DSI_REACH;
- MsgCaClient.Word2 = nDataLength;
- OTA_CLIENT_Service (&MsgCaClient);
- break;
- }
-
- return;
- }
- /**************************************************************************************
- PsiFilterSetup
- Description: Set up psi filter for section receiving
- Input: lFilterId - filter ID
- lPid, lTableId, lTableIdExt, lVersion, lSectionNumber: when set as UNSET_PARAM,
- then this parameter unused. If lVersion setted, version check function
- would be launched.
- Output:
- None
- Return:
- None
- **************************************************************************************/
- static StbErr_t PsiFilterSetup(DMX_FilterID lFilterId, UInt16 lPid,
- UInt16 lTableId, UInt16 lTableIdExt,
- UInt16 lVersion, UInt16 lSectionNumber, CaClientFilterEnum Num)
- {
- unsigned char byte1, byte2;
- StbErr_t sErr = Err_OK;
-
- KB_DmxControlChnnl(channelID, KB_DMX_START);
- memset(_uSectionHardMask, 0, 8);
-
- if(lTableId != UNSET_PARAM)
- {
- _uSectionHardMask[0] = 0xff;
- _uSectionHardValue[0] = (UCHAR)lTableId;
- }
- if(lTableIdExt != UNSET_PARAM)
- {
- byte1 = (UCHAR)((lTableIdExt >> 8) & 0xff);
- byte2 = (UCHAR)(lTableIdExt & 0xff);
-
- _uSectionHardMask[3] = 0xff;
- _uSectionHardMask[4] = 0xff;
- _uSectionHardValue[3] = byte1;
- _uSectionHardValue[4] = byte2;
- if(lTableId == 0xfe && byte2 == 0xff)
- {
- _uSectionHardMask[2] = 0x00;
- }
- }
- if(lVersion != UNSET_PARAM)
- {
- _uSectionHardMask[5] = 0x02;
- _uSectionHardValue[5] = (UInt8)(~lVersion);
- }
- if(lSectionNumber != UNSET_PARAM)
- {
- _uSectionHardMask[6] = 0xff;
- _uSectionHardValue[6] = (UInt8)lSectionNumber;
- }
- #if 0
- printf("nvalue[8]={%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x}", _uSectionHardValue[0], _uSectionHardValue[1],_uSectionHardValue[2], _uSectionHardValue[3],
- _uSectionHardValue[4], _uSectionHardValue[5],_uSectionHardValue[6], _uSectionHardValue[1]);
- printf("nmask[8]= {%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x}", _uSectionHardMask[0], _uSectionHardMask[1],_uSectionHardMask[2], _uSectionHardMask[3],
- _uSectionHardMask[4], _uSectionHardMask[5],_uSectionHardMask[6], _uSectionHardMask[1]);
- #endif
- KB_DmxSetChnnlPID(channelID, lPid);
- sErr = KB_DmxSetFilterByType(lFilterId, _uSectionHardValue, _uSectionHardMask, 0, STPTI_FILTER_REPEAT_MODE_STPTI_FILTER_REPEATED/*STPTI_FILTER_REPEAT_MODE_STPTI_FILTER_ONE_SHOT*/);
- if(Err_OK != sErr)
- {
- return sErr;
- }
-
- return (sErr);
- }
- void test3()
- {
- char *pszInfo;
- char buf[40];
- if(KB_Flash_lc_MSGBox(NULL)==IDOK)
- {
- printf("n test3: seclect ok");
- pszInfo="升级过程大致需要%d分钟,5秒后开始升级。";
- if(pszInfo != NULL)
- sprintf(buf, pszInfo, 9);
- KB_Flash_lc_MSGBox(buf);
- }
- else
- printf("n test3:seclect exit");
- }
- /**************************************************************************************
- CA_CLIENT_Init
- Description: CA Client Initialization,
- Input: None
- Output: None
- Return: None
- Error Debug: Enabled.
- **************************************************************************************/
- void OTA_CLIENT_Init(void)
- {
- StbErr_t Ret;
- KB_OSPRet res;
- printf("nn---------[huqs]:OTA_CLIENT_Init()-----------");
- #ifdef OTA_TEST1
- {
- FePara(0);
- }
- #endif
-
- //read loader infomation from STB
- ReadHLLoaderParams();
-
- // Message queue create. Task create
- res = KB_OSPQueInit("OTA", OTA_CLIENT_QUEUE_SIZE, &_hQueue);
- res = KB_OSPQueInit("OTA2", OTA_CLIENT_QUEUE_SIZE, &_OtaQueue);
- res|= KB_OSPTaskInit("OTA", OTA_CLIENT_STACK_SIZE, OTAClientTask, OTA_CLIENT_PRIORITY, NULL, &_hTask);
- if(res!= Ret_OK)
- {
- Print("[OTA Client]Error: create OTA client task failed.n");
- }
- //timer
- _lDownloadTimer = KB_TimerCreate(KB_TIMER_REPEAT, (KB_TIMER_FUNC_POINTER)DownloadTimerCallback, NULL);
- //setup filter for BAT processing
- Kb_dmux_init();
- //Ret = KB_PsiFilter_Setup(_lOTAFilter, 0x11, 0x4A, 0xff00, UNSET_PARAM, 0, L_SCT_BAT);
- //if(Ret != TM_OK)
- //{
- // Print("n[OTA Client]Error: set filter for BAT failed.n");
- //}
- }
- /*************************************************************************************
- KB_DCFilter_Service
- Description:
- Input: dummy - unused parameter
- Output: None
- Return: None
- *************************************************************************************/
- INT32 KB_DCFilter_Service(unsigned short pid)
- {
- INT32 HdmxRet;
- UInt32 Freq, Symb, Qam;
- printf("n -KB_DCFilter_Service-");
-
- OTA_CLIENT_GetDLTuneParams(&Freq, &Symb, &Qam);
- #ifdef OTA_TEST1
- if(KB_CHN_SetQam(299000000, 6875000, 3)==0)
- #else
- if(KB_CHN_SetQam(Freq, Symb, Qam)==0)
- #endif
- {
- printf("n KB_DCFilter_Service: setqam(%ld) ok!", Freq);
- HdmxRet = KB_PsiFilter_Setup(_lOTAFilter, pid, 0x3b, UNSET_PARAM, UNSET_PARAM,0, L_SCT_DSI);
- if(HdmxRet != TM_OK)
- {
- Print("n[OTA Client]Error: set filter for DII failed.");
- }
- }
- else
- {
- printf("nn-------- KB_DCFilter_Service: can't setqam(%ld)", Freq);
- KB_Timer_Stop(_lDownloadTimer);
- OSA_wait(1000);
- KB_ErrorMsg(IRD_DL_CONN_FAIL);
-
- KB_UpdateCheckClear();
-
- }
-
- return HdmxRet;
- }
- /*************************************************************************************
- CAClientTask
- Description: CA Client task processing function
- Input: dummy - unused parameter
- Output: None
- Return: None
- *************************************************************************************/
- static void OTAClientTask(void * dummy)
- {
- KB_OSPMsgNode Msg;
- UInt16 pmtPid, ctrlPid;
- KB_OSPMsgNode MsgCaClient;
- INT32 HdmxRet;
- static UInt8 current_section=0;
- char *info;
- int otatype;
- int ota_count = 0;
- INT32 status;
- int nres=-1;
- printf("rnn------OTAClientTask------");
- UNUSED_PARAMETER2(dummy);
- _flag_Download_Allowed = 1;
-
- while(1)
- {
- status = KB_OSPMsgGet(_hQueue, KB_Wait, 0, &Msg);
- if(status != Ret_OK)
- {
- continue;
- }
-
- if(_bDownloadChecking == True)
- {
- switch(Msg.Word1)
- {
- //*****************************
- case E_DOWNLOAD_SEARCHING:
- //*****************************
- Print ("nnE_DOWNLOAD_SEARCHING");
-
- //reset timer
- _TimerCount = 27; _TimerFlag = True;
- KB_Timer_Start(_lDownloadTimer, 1000);
-
- OSA_wait(20);
- HdmxRet = KB_PsiFilter_Setup(_lOTAFilter, 0, 0, UNSET_PARAM, UNSET_PARAM, 0, L_SCT_PAT);
- if(HdmxRet != TM_OK)
- {
- Print("n[OTA Client]Error: set filter for pat failed.n");
- }
- OSA_wait(100);
- break;
-
- //*****************************
- case E_PAT_REACH:
- //*****************************
- Print ("n---E_PAT_REACH---");
- pmtPid = ExtractDlPmtPidFromPat();
- printf("n-pmtPid=%04x",pmtPid);
- if (pmtPid != 0x1FFF)
- {
- KB_PsiFilter_Setup(_lOTAFilter, pmtPid, 0x02, UNSET_PARAM, UNSET_PARAM, 0, L_SCT_LPMT);
-
- }
- else
- {
- KB_Timer_Stop(_lDownloadTimer);
- OSA_wait(200);
- KB_ErrorMsg(IRD_DL_NOT_PRESENT);
- }
-
- break;
-
- //*****************************
- case E_DSI_REACH:
- //*****************************
- Print ("n---E_DSI_REACH---");
- if(_pManuDlLinkage!=NULL&&_bDownloadComparing)
- {
- _bOnlyStopTimer = True;
- nres = StbStreamPara_Compare(ctrlPid);
- if(nres>0)
- {
- printf("n StbStreamPara_Compare>0, ok");
- FePara(0);
- ota_count = 0;
- KB_ErrorMsg(IRD_DL_PRESENT);
- _bDownloadChecking = False;
- }
- else
- {
- printf("n StbStreamPara_Compare<0, error, res=%d", nres);
- KB_Timer_Stop(_lDownloadTimer);
- OSA_wait(200);
-
- if(nres==-1||nres==-2||nres==-3)
- KB_ErrorMsg(IRD_DL_PARA1_NOT_EQUAL);
- else if(nres==-4)
- KB_ErrorMsg(IRD_DL_PARA2_NOT_EQUAL);
-
- OSA_wait(200);
- KB_OSD_ClearAll(0xf000);
- _bDownloadChecking = False;
- }
- }
-
- break;
-
- //*****************************
- case E_PMT_REACH:
- //*****************************
- Print ("n---E_PMT_REACH---");
- KB_Timer_Stop(_lDownloadTimer);
- _TimerCount = 26; _TimerFlag = False; //for control section
- MSG_RemainTimeDisplay(_TimerCount, _TimerFlag);
- KB_Timer_Start(_lDownloadTimer, 1000);
-
- ctrlPid = ExtractDLPidFromPMT();
- _dlPid = ctrlPid;
- printf("n--ctrlpid=%x",ctrlPid);
- if(ctrlPid == 0x1FFF)
- {
- KB_Timer_Stop(_lDownloadTimer);
- OSA_wait(200);
- KB_ErrorMsg(IRD_DL_NOT_PRESENT);
- _bDownloadChecking = False;
- }
- else
- {
- #ifdef OTA_TEST1
- KB_DCFilter_Service(0x80);
- #else
- KB_DCFilter_Service(ctrlPid);
- #endif
- _bDownloadComparing = True;
- }
-
- break;
-
- }
-
- }
-
- else
- {
- switch (Msg.Word1)
- {
- //*****************************
- case E_DOWNLOAD_CHECKING:
- //*****************************
- Print ("nn[CaClientTask]:begin to E_DOWNLOAD_CHECKING");
- if(GetDLTuneParams()==0)
- {
- if(KB_BeginDownloadSearching()<0)
- _bDownloadChecking = False;
- else
- _bDownloadChecking = True;
- }
- else if(GetDLTuneParams()<0)
- {
- if(Msg.Word2== True)
- {
- _bDownloadChecking = False;
- KB_ErrorMsg(IRD_DL_NIT_FAIL);
- }
- }
-
- break;
-
- //*****************************
- case E_STOP_CURRENT_SERVICE:
- //*****************************
- Print ("n[CaClientTask] E_STOP_CURRENT_SERVICEn");
- if(_bPmtFirst == False)
- {
- if (DmuxDrvDebugMsgLvl & 0x10)
- Print ("{Send to CA_TASK} CA_CLIENT__STOP_SERVICEn");
- }
- break;
-
- //*****************************
- case E_NEW_TS_ASSOCIATED:
- //*****************************
- printf ("n--[OTAClientTask] E_NEW_TS_ASSOCIATEDn");
- HdmxRet = KB_PsiFilter_Setup(_lOTAFilter, 0x11, 0x4A, 0xff00, UNSET_PARAM, 0, L_SCT_BAT);
- if(HdmxRet != TM_OK)
- {
- printf("n[OTA Client]Error: set filter for BAT failed.n");
- }
-
- _bCurrentBatValid = False;
- _pManuDlLinkage = NULL;
- break;
-
- //*****************************
- case E_CURRENT_TS_DEASSOCIATED:
- //*****************************
- printf ("n[CaClientTask] E_CURRENT_TS_DEASSOCIATEDn");
- HPIv2_HDMX_FilterStop();
- break;
-
-
- //*****************************
- case E_BAT_REACH:
- //*****************************
- Print ("n[OTAClientTask] E_BAT_REACH: updatePrevent=%d", updatePrevent);
- if(KB_OTA_IsPermit()==FALSE) break;
-
- _bCurrentBatValid = True;
- ExtraceTFLinkage();
- ExtractManuDlLinkageEx();
- if(_pManuDlLinkage==NULL)
- {
- printf("n _pManuDlLinkage=NULL");
- //KB_UpdatePreventSet(True);
- KB_OTAManuEnableSet(False);
- KB_UpdateCheckClear();
- break;
- }
-
- if(!OTA_CLIENT_GetDownloadState())
- {
- SetUpdateSearchStatus(FALSE);
- break;
- }
-
- //启动nit 搜索
- MsgCaClient.Word1 = E_FILTER_SETPU;
- MsgCaClient.Word2 = E_NIT_FILTER_SETUP;
- MsgCaClient.Word3 = current_section;
- OTA_CLIENT_Service (&MsgCaClient);
- break;
- //*****************************
- case E_FILTER_SETPU:
- //*****************************
- Print ("nn-[OTAClientTask]- E_FILTER_SETPU ----current_section= %ld",Msg.Word3);
- if(Msg.Word2==E_NIT_FILTER_SETUP)
- {
- //HPIv2_HDMX_FilterStop();
- HdmxRet = KB_PsiFilter_Setup(_lOTAFilter, 0x10, 0x40, UNSET_PARAM, UNSET_PARAM, Msg.Word3, L_SCT_NIT);
- if(HdmxRet != TM_OK)
- {
- Print("n[OTA Client]Error: set filter for NIT failed.");
- }
- }
- else if(Msg.Word2 == E_PAT_FILTER_SETUP)
- {
- HPIv2_HDMX_FilterStop();
- HdmxRet = KB_PsiFilter_Setup(_lOTAFilter, 0, 0, UNSET_PARAM, UNSET_PARAM, 0, L_SCT_PAT);
- if(HdmxRet != TM_OK)
- {
- Print("n[OTA Client]Error: set filter for PAT failed.");
- }
- }
-
- OSA_wait(100);
-
- break;
- //*****************************
- case E_NIT_REACH:
- //*****************************
- Print ("nn-[OTAClientTask] E_NIT_REACH ");
-
- if(KB_OTA_IsPermit()==FALSE) break;
- memcpy(_shareNitSection, _bakNitSection, Msg.Word2);
- _bCurrentNitValid = True;
-
- //搜到nit后启动检查
- if(_bCurrentNitValid == True)
- {
- if(_pManuDlLinkage != NULL)
- {
- SetUpdateSearchStatus(TRUE);
- if(_pManuDlLinkage->control_byte_2 == 1 || _pManuDlLinkage->control_byte_2 == 2)
- {
- otatype =GetUpgradeType(_pManuDlLinkage);
- printf("n otatype=%d", otatype);
- if(otatype==OTA_INVALID)
- {
- KB_UpdatePreventSet(True);
- KB_OTAManuEnableSet(False);
-
- //stop the filter
- KB_UpdateCheckClear();
- break;
- }
- else
- {
- KB_UpdatePreventSet(False);
- KB_OTAManuEnableSet(True);
- }
- if(g_menu_ota)
- otatype = OTA_USER_CONFORMED;
- //关闭当前后续和频道列表
- KB_CurMovie_DispClear();
-
- //强制升级
- if(otatype==OTA_FORCED)
- {
-
- printf("nE_NIT_REACH reach, and start download checking.");
- MsgCaClient.Word1 = E_DOWNLOAD_CHECKING;
- MsgCaClient.Word2 = TRUE; //show the error message
- OTA_CLIENT_Service (&MsgCaClient);
-
- KB_OTARunSet(True);
- g_menu_ota =FALSE;
- }
- //用户许可升级
- else if(otatype==OTA_USER_CONFORMED)
- {
- KB_OTARunSet(True);
- g_menu_ota =FALSE;
- if(ota_count>0)
- break;
- ota_count ++;
- if(KB_Flash_lc_MSGBox(NULL) == IDOK)
- {
- printf("n user seclect to update! go E_DOWNLOAD_CHECKING");
- OSA_wait(200);
- MsgCaClient.Word1 = E_DOWNLOAD_CHECKING;
- MsgCaClient.Word2 = TRUE; //show the error message
- OTA_CLIENT_Service (&MsgCaClient);
- }
- else
- {
- KB_Flash_lc_MSGBox_Close();
- KB_OSD_ClearAll(0xF000);
- OSA_wait(200);
- otatype = OTA_MANUL;
- KB_UpdatePreventSet(True);
- DTV_EPG_SetToLastProg();
- }
-
- }
- ota_count =0;
- //手动升级
- if(otatype==OTA_MANUL)
- {
- printf("n 手动升级");
- KB_UpdateCheckClear();
-
- break;
- }
-
- }
-
- }
- else
- {
- printf("n error: _pManuDlLinkage=NULL!");
- SetUpdateSearchStatus(FALSE);
- KB_OTAManuEnableSet(False);
- }
- }
- break;
-
- //*****************************
- case E_TDT_REACH:
- //*****************************
- break;
-
- }
-
- }
-
- }
- }
- static void DownloadTimerCallback (void)
- {
- _TimerCount --;
- printf("n%ld _bOnlyStopTimer=%d",_TimerCount, _bOnlyStopTimer);
- if(_TimerCount<6) //end
- {
- //SetLockOTAStartFlag(False);
- updateLock = False;
-
- //stop pat, pmt filter, control section filter
- if(_TimerFlag == True) //pmt pat parse
- {
- printf("n_TimerFlag=True");
-
- KB_ErrorMsg(IRD_DL_SVC_FAIL);
- }
- else
- {
- printf("n_TimerFlag=false _bOnlyStopTimer=%d", _bOnlyStopTimer);
- HPIv2_HDMX_FilterStop();
- if(_bOnlyStopTimer != True)
- {
- KB_ErrorMsg(IRD_DL_NOT_PRESENT);
- KB_Timer_Stop(_lDownloadTimer);
- }
- else
- {
- KB_Timer_Stop(_lDownloadTimer);
- _bOnlyStopTimer = False;
- }
- }
- printf("n--a men");
- _bDownloadChecking = False;
-
- }
- else
- {
- MSG_RemainTimeDisplay(_TimerCount, _TimerFlag);
- KB_Timer_Start(_lDownloadTimer, 1000);
- }
- }
- // read ota parameter from 0xB8040000 start
- TFLoaderPara * ReadHLLoaderParams(void)
- {
- INT32 Status;
- UInt8 *buf;
- TFLoaderPara *kbpara;
- int i;
- buf = OTAParabuf;
- Status = KB_E2PRead((UINT32)KB_NVM_UPDATE_SERIAL_OFFSET, (UINT8 *)buf, 68, NULL);
- #if 0
- printf("n----ReadHLLoaderParams start------");
- for(i=0;i<48;i++)
- {
- printf("%02x ",buf[i]);
- if((i+1)%15==0)
- printf("n");
- }
- printf("n----ReadHLLoaderParams end------");
- #endif
- kbpara = &gKBloaderPara;
- //if((buf[9]==0x69))
- {
- kbpara->KB_MANUFACTURER_ID = buf[9];
- kbpara->STB_SERIAL_NO = buf[10]*256*256*256 + buf[11]*256*256 +buf[12]*256 +buf[13];
- kbpara->KB_HARDWARE_VERSION_NUMBER = buf[14];
- kbpara->KB_HARDWARE_MAJOR_VERSION_NUMBER = buf[15]*256 + buf[16];
- kbpara->KB_HARDWARE_MINOR_VERSION_NUMBER = buf[17]*256 + buf[18];
- kbpara->KB_HARDWARE_BATCH_NO = buf[19]*256 + buf[20];
- kbpara->LOAD_SEQUENCE_NUMBER = buf[21]*256 + buf[22];
- kbpara->KB_SOFTWARE_MAJOR_VERSION_NUMBER = buf[23]*256 + buf[24];
- kbpara->KB_SOFTWARE_MINOR_VERSION_NUMBER = buf[25]*256 + buf[26];
- kbpara->kB_REGION_CODE = buf[27]*256 + buf[28];
- kbpara->kB_KeY_TYPE = buf[29];
-
- kbpara->IMAGE_SIZE = buf[1]*256*256*256 + buf[2]*256*256 + buf[3]*256 +buf[4];
-
- kbpara->SIGN_DATE.year = BCDtoINT(buf[30])*100 + BCDtoINT(buf[31]);
- kbpara->SIGN_DATE.month = BCDtoINT(buf[32]);
- kbpara->SIGN_DATE.day= BCDtoINT(buf[33]);
-
- kbpara->SIGN_TIME.hour = BCDtoINT(buf[34]);
- kbpara->SIGN_TIME.minute= BCDtoINT(buf[35]);
- #if 0
- kbpara->DLOAD_DATE.year = BCDtoINT(buf[36])*100 + BCDtoINT(buf[37]);
- kbpara->DLOAD_DATE.month = BCDtoINT(buf[38]);
- kbpara->DLOAD_DATE.day= BCDtoINT(buf[39]);
- kbpara->DLOAD_TIME.hour = BCDtoINT(buf[40]);
- kbpara->DLOAD_TIME.minute= BCDtoINT(buf[41]);
- kbpara->DLOAD_TIME.second = BCDtoINT(buf[42]);
- kbpara->DLOAD_DUR = buf[43]*256 + buf[44];
- #endif
- }
- #if 1 /*test*/
-
- printf("n--------------------------n");
- printf(" IMAGE_SIZE = %x.n", kbpara->IMAGE_SIZE);
- printf(" LOAD_SEQUENCE_NUMBER = %x.n", kbpara->LOAD_SEQUENCE_NUMBER);
- printf(" KB_MANUFACTURER_ID = %x.n", kbpara->KB_MANUFACTURER_ID);
- printf(" STB_SERIAL_NO = %x.n", kbpara->STB_SERIAL_NO);
- printf(" KB_HARDWARE_BATCH_NO = %x.n", kbpara->KB_HARDWARE_BATCH_NO);
- printf(" KB_HARDWARE_VERSION_NUMBER = %x.n", kbpara->KB_HARDWARE_VERSION_NUMBER);
- printf(" KB_HARDWARE_MAJOR_VERSION_NUMBER = %x.n", kbpara->KB_HARDWARE_MAJOR_VERSION_NUMBER);
- printf(" KB_HARDWARE_MINOR_VERSION_NUMBER = %x.n", kbpara->KB_HARDWARE_MINOR_VERSION_NUMBER);
- printf(" KB_SOFTWARE_MAJOR_VERSION_NUMBER = %x.n", kbpara->KB_SOFTWARE_MAJOR_VERSION_NUMBER);
- printf(" KB_SOFTWARE_MINOR_VERSION_NUMBER = %x.n", kbpara->KB_SOFTWARE_MINOR_VERSION_NUMBER);
- printf(" kB_REGION_CODE = %x.n", kbpara->kB_REGION_CODE);
- printf(" kB_KeY_TYPE = %x.n", kbpara->kB_KeY_TYPE);
-
- printf(" sign: %d-%d-%d: %d-%dn", kbpara->SIGN_DATE.year,kbpara->SIGN_DATE.month, kbpara->SIGN_DATE.day, kbpara->SIGN_TIME.hour, kbpara->SIGN_TIME.minute);
- printf(" dload: %d-%d-%d: %d-%d-%dn", kbpara->DLOAD_DATE.year,kbpara->DLOAD_DATE.month, kbpara->DLOAD_DATE.day, kbpara->DLOAD_TIME.hour, kbpara->DLOAD_TIME.minute, kbpara->DLOAD_TIME.second);
- printf(" dload_dur: %dn",kbpara->DLOAD_DUR);
- printf("n--------------------------n");
-
- #endif
- return kbpara;
- }
- Bool OTA_CLIENT_GetDLTuneParams(UInt32 * olFreq, UInt32 * olSymb, UInt32 * olModulate)
- {
- *olFreq = _dlFreq;
- *olSymb = _dlSymb;
- *olModulate = _dlQam;
-
- #ifdef OTA_TEST2
- *olFreq = 299000000;
- *olSymb = 6875000;
- *olModulate = 3;
- #endif
-
- return True;
- }
- static int GetDLTuneParams(void)
- {
- UInt8 * readPtr;
- Int32 dataLength;
- Int32 network_descriptors_length, transport_stream_loop_length,transport_descriptors_length;
- UInt16 transport_stream_id, original_network_id;
- Int32 tempLength;
- UInt8 * tempP;
- UInt8 last_section, current_section;
- Int32 sectionLength;
- UInt8 tableid;
- KB_OSPMsgNode MsgCaClient;
- if(_bCurrentNitValid == False)
- return False;
- if(_bCurrentBatValid == False)
- return False;
- if(_pManuDlLinkage == NULL)
- return False;
- //Parse nit for freq, symb and modulate. _shareNitSection
- readPtr = _shareNitSection;
-
- current_section = readPtr[6] ;
- last_section = readPtr[7];
- dataLength = (readPtr[1] & 0x0f)*256 + readPtr[2] + 3 - 4; /*4 - crc32 */
- sectionLength = dataLength;
- tableid = readPtr[0];
-
- readPtr += 8;
- dataLength -= 8;
-
- //to network_descriptors_length
- network_descriptors_length = (readPtr[0] & 0x0f) * 256 + readPtr[1];
- readPtr += (network_descriptors_length + 2);
- dataLength -= (network_descriptors_length + 2);
- if(dataLength <= 0) return False;
- //to transport_stream_loop_length
- transport_stream_loop_length = (readPtr[0] & 0x0f) * 256 + readPtr[1];
- readPtr += 2;
- dataLength -= 2;
- while(transport_stream_loop_length > 0)
- {
- transport_stream_id = readPtr[0] * 256 + readPtr[1];
- original_network_id = readPtr[2] * 256 + readPtr[3];
- transport_descriptors_length = (readPtr[4] & 0x0f) * 256 + readPtr[5];
-
- printf("nn---[GetDLTuneParams1]:transport_stream_id=%x, original_network_id=%x, len = %d.", transport_stream_id, original_network_id, transport_descriptors_length);
- printf("n---[GetDLTuneParams2]:transport_stream_id=%x, original_network_id=%x", _pManuDlLinkage->transport_stream_id, _pManuDlLinkage->original_network_id);
- if(transport_stream_id == _pManuDlLinkage->transport_stream_id
- && original_network_id == _pManuDlLinkage->original_network_id)
- {
- UInt8 desTag, desLen;
-
- tempLength = transport_descriptors_length;
- tempP = (readPtr + 6);
-
- while(tempLength > 0)
- {
- desTag = tempP[0];
- desLen = tempP[1];
-
- if(desTag == 0x44)
- {
- _dlFreq = (((tempP[2]/16)*10 + (tempP[2]&0x0f)) * 1000000 +
- ((tempP[3]/16)*10 + (tempP[3]&0x0f))*10000 +
- ((tempP[4]/16)*10 + (tempP[4]&0x0f))*100 +
- ((tempP[5]/16)*10 + (tempP[5]&0x0f)))*100;
- _dlSymb = (((tempP[9]/16)*10 + (tempP[9]&0x0f)) * 100000 +
- ((tempP[10]/16)*10 + (tempP[10]&0x0f))*1000 +
- ((tempP[11]/16)*10 + (tempP[11]&0x0f))*10 +
- (tempP[12]/16))*100;
- //_dlQam = (tempP[8] + HPIv2_eDemodConstellationQam16 - 1);
- _dlQam = (tempP[8]);
- printf("n --GetDLTuneParams:(%d, %d, %d).", _dlFreq, _dlSymb, _dlQam);
- return 0;
- }
-
-
- tempP += (2 + desLen);
- tempLength -= (2 + desLen);
- }
-
- }
-
- readPtr += (6 + transport_descriptors_length);
- dataLength -= (6 + transport_descriptors_length);
- transport_stream_loop_length -= (6 + transport_descriptors_length);
- //printf("n---[GetDLTuneParams1]:transport_stream_loop_length= %d.", transport_stream_loop_length);
-
- }
- if ( current_section<last_section)
- {
- current_section++;
- //启动nit 搜索
- MsgCaClient.Word1 = E_FILTER_SETPU;
- MsgCaClient.Word2 = E_NIT_FILTER_SETUP;
- MsgCaClient.Word3 = current_section;
- OTA_CLIENT_Service (&MsgCaClient);
- return 1;
- }
-
- return -1;
- }
- void SetLockOTAStartFlag(BOOL flag)
- {
- updateLock = flag;
- }
-
- BOOL GetLockOTAFlag(void)
- {
- return updateLock;
- }
- // 1: push 0 : pop
- void BQ_TF_ShowConnectInfo(char *DisplayStr,int ShowFlag)
- {
- static int flag=0;
- static char buf[200];
-
- if(ShowFlag==1)
- {
- if(!_bDownloadTrigger)
- {
- //BQ_MSG_Show(DisplayStr, BT_NONE, MSGB_WAIT_FOREVER,0);
- KB_Flash_lc_MSGBox(DisplayStr);
-
- }
- else
- {
- flag = 1;
- strcpy(buf,DisplayStr);
- }
- }
- else
- {
- if(flag == 1)
- {
- //BQ_MSG_Box(buf, BT_NONE, MSGB_WAIT_FOREVER,0);
- KB_Flash_lc_MSGBox(DisplayStr);
- flag = 0;
- }
- }
- }
- void MSG_RemainTimeDisplay(Int32 second, Bool flag)
- {
- char buf[100];
- char *pszInfo;
- //nLangType=BQ_Browser_Language();
- if(flag == TRUE)
- {
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType,BQ_PROMPTMSSG,BQ_PROMPTMSSG_19);
- pszInfo = "正在连接下载流... (剩余%02d秒)";
- if(pszInfo != NULL)
- sprintf(buf, pszInfo, second);
- BQ_TF_ShowConnectInfo(buf,1);
- }
- else
- {
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType,BQ_PROMPTMSSG,BQ_PROMPTMSSG_20);
- pszInfo= "正在分析下载流... (剩余%02d秒)";
- if(pszInfo != NULL)
- sprintf(buf, pszInfo, second);
- BQ_TF_ShowConnectInfo(buf,1);
- }
- return;
- }
- //
- // KB_ErrorMsg:显示错误信息
- //
- void KB_ErrorMsg(UInt16 code)
- {
- char *pszInfo;
- //nLangType=BQ_Browser_Language();
- _Error_Code = code;
- printf("n ------KB_ErrorMsg-: %d",code);
- UnLockPlayPgm();
- if(_Error_Code == IRD_DL_NIT_FAIL)
- {
- if(!_bDownloadTrigger)
- {
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType,BQ_PROMPTMSSG,BQ_PROMPTMSSG_11);
- pszInfo = "查找下载服务的调谐参数失败!";
- KB_Flash_lc_MSGBox(pszInfo);
- _bDownloadTrigger = False;
- }
- SetUpdateSearchStatus(FALSE);
- OSA_wait(5000);
- KB_KEY_SetReceive(1);
- KB_AV_PlayStart();
- KB_OSD_ClearAll(0xF000);
- UnLockPlayPgm();
- DTV_EPG_SetToLastProg();
- printf("Please resume play here...n");
- }
- else if(_Error_Code == IRD_DL_SVC_FAIL)
- {
- if(!_bDownloadTrigger)
- {
- OSA_wait(500);
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType, BQ_PROMPTMSSG, BQ_PROMPTMSSG_12);
- pszInfo = "连接下载流失败! 5秒后消失。";
- KB_Flash_lc_MSGBox(pszInfo);
- }
- SetUpdateSearchStatus(FALSE);
- OSA_wait(5000);
- KB_KEY_SetReceive(1);
- KB_AV_PlayStart();
- KB_OSD_ClearAll(0xF000);
- UnLockPlayPgm();
- DTV_EPG_SetToLastProg();
- printf("Please resume play here...n");
-
- }
- else if(_Error_Code == IRD_DL_CONN_FAIL)
- {
- if(!_bDownloadTrigger)
- {
- OSA_wait(500);
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType, BQ_PROMPTMSSG, BQ_PROMPTMSSG_12);
- pszInfo = "不能锁定升级流所在频点,放弃升级。";
- KB_Flash_lc_MSGBox(pszInfo);
- }
- SetUpdateSearchStatus(FALSE);
- OSA_wait(5000);
- KB_KEY_SetReceive(1);
- KB_AV_PlayStart();
- KB_OSD_ClearAll(0xF000);
- UnLockPlayPgm();
- DTV_EPG_SetToLastProg();
- printf("Please resume play here...n");
-
- }
- else if(_Error_Code == IRD_DL_NOT_PRESENT)
- {
- if(!_bDownloadTrigger)
- {
- OSA_wait(500);
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType,BQ_PROMPTMSSG,BQ_PROMPTMSSG_13);
- pszInfo = "下载流无效! 5秒后消失.";
- KB_Flash_lc_MSGBox(pszInfo);
- }
- SetUpdateSearchStatus(FALSE);
- OSA_wait(5000);
- KB_KEY_SetReceive(1);
- KB_AV_PlayStart();
- KB_OSD_ClearAll(0xF000);
- DTV_EPG_SetToLastProg();
- printf("Please resume play here ...n");
- }
- //add by shriek
- else if(_Error_Code == IRD_DL_PARA1_NOT_EQUAL)
- {
- printf("n IRD_DL_PARA1_NOT_EQUAL");
- if(!_bDownloadTrigger)
- {
- OSA_wait(500);
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType,BQ_PROMPTMSSG,BQ_PROMPTMSSG_36);
- pszInfo = "参数错误(0001), 放弃此次升级!";
- KB_Flash_lc_MSGBox(pszInfo);
- }
- SetUpdateSearchStatus(FALSE);
- OSA_wait(5000);
- KB_KEY_SetReceive(1);
- KB_AV_PlayStart();
- KB_OSD_ClearAll(0xF000);
- DTV_EPG_SetToLastProg();
- printf("Please resume play here ...n");
- }
- else if(_Error_Code == IRD_DL_PARA2_NOT_EQUAL)
- {
- printf("n IRD_DL_PARA2_NOT_EQUAL");
- if(!_bDownloadTrigger)
- {
- OSA_wait(500);
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType,BQ_PROMPTMSSG,BQ_PROMPTMSSG_37);
- pszInfo = "参数错误(0002), 放弃此次升级!";
- KB_Flash_lc_MSGBox(pszInfo);
- }
- SetUpdateSearchStatus(FALSE);
- OSA_wait(5000);
- KB_KEY_SetReceive(1);
- KB_AV_PlayStart();
- KB_OSD_ClearAll(0xF000);
- DTV_EPG_SetToLastProg();
-
- printf("Please resume play here ...n");
- }
- //shriek end
- else if(_Error_Code == IRD_DL_PRESENT)
- {
- char buf[40];
- if(!_bDownloadTrigger)
- {
- printf("n---begin while");
- while(1)
- {
- printf("nupdateLock=%d GetLockOTAFlag()=%d",updateLock,GetLockOTAFlag());
- if(!GetLockOTAFlag()||!updateLock)
- {
- printf("n--------break
");
- break;
- }
- }
- printf("n---out of while");
- //pszInfo=OSD_GetLanguageInfoAddr(nLangType,BQ_PROMPTMSSG,BQ_PROMPTMSSG_14);
- pszInfo="升级过程大致需要%d分钟,5 秒后开始升级";
- if(pszInfo != NULL)
- sprintf(buf, pszInfo, _pManuDlLinkage->time);
- KB_Flash_lc_MSGBox(buf);
-
- OSA_wait(5000);
- KB_KEY_SetReceive(1);
-
- //将部分更新的参数备份
- WriteHLLoaderParams();
- printf("n -----begin to start KB_Restart()-----");
- KB_Restart();
- }
-
- }
- KB_OTARunSet(False);
- KB_UpdatePreventSet(True);
- KB_Flash_lc_MSGBox_Close();
-
- return;
- }
- void WriteHLLoaderParams(void)
- {
- UInt8 buf[4], buf2[4];
- printf("n -----WriteHLLoaderParams-----");
- buf[0] = (_pManuDlLinkage->major_sw_version>>8)&0x00ff;
- buf[1] = ( _pManuDlLinkage->major_sw_version)&0x00ff;
- buf[2] = (_pManuDlLinkage->minor_sw_version>>8)&0x00ff;
- buf[3] = ( _pManuDlLinkage->minor_sw_version)&0x00ff;
- printf("rn[_LOADER_111]: major: %x %x minor: %x %x", buf[0],buf[1],buf[2],buf[3]);
- if(KB_E2PWrite(KB_NVM_UPDATE_SW_MAJOR_VERSION_BACKUP_OFFSET, buf, 4, NULL)!=Ret_OK)
- {
- printf("n Save OTA parameter error!");
- }
- #if 1
- KB_E2PRead((UINT32)KB_NVM_UPDATE_SW_MAJOR_VERSION_BACKUP_OFFSET, (UINT8 *)buf2, (UINT32)4, NULL);
- printf("rn[_LOADER_222]: major: %x %x minor: %x %x", buf2[0],buf2[1],buf2[2],buf2[3]);
- #endif
-
- }
- static UInt16 ExtractDLPidFromPMT(void)
- {
- UInt8 * readPtr;
- Int32 dataLength;
- UInt16 ctrlPid;
- Int32 program_info_length;
- Int32 ES_info_length;
- readPtr = _bakdlPmtSection;
- dataLength = (readPtr[1] & 0x0f)*256 + readPtr[2] + 3 - 4; /* 4 - crc32 */
- readPtr += 8;
- dataLength -= 8;
-
- program_info_length = (readPtr[2] & 0x0f) * 256 + readPtr[3];
- readPtr += 4;
- dataLength -= 4;
- ctrlPid = 0x1FFF;
- readPtr += program_info_length;
- dataLength -= program_info_length;
- while(dataLength > 0)
- {
- printf("nstream type = 0x%x.", readPtr[0]);
- ctrlPid = (UInt16)(((UInt16)readPtr[1] & 0x1f) * 256 + (UInt16)readPtr[2]);
- printf("npid = %x.n", ctrlPid);
- if(readPtr[0] == 0x80 || readPtr[0] == 0x82 || readPtr[0] == 0x84)
- {
- return ctrlPid;
- }
- ES_info_length = (readPtr[3] & 0x0f) * 256 + readPtr[4];
- // printf("es length = %d.n", ES_info_length);
- readPtr += (5 + ES_info_length);
- dataLength -= (5 + ES_info_length);
- }
-
- return ctrlPid;
- }
- static UInt16 ExtractDlPmtPidFromPat(void)
- {
- UInt8 * readPtr;
- Int32 dataLength;
- UInt16 pmtPid;
- readPtr = _bakPatSection;
- dataLength = (readPtr[1] & 0x0f)*256 + readPtr[2] + 3 - 4; /* 4 - crc32 */
- readPtr += 8;
- dataLength -= 8;
- pmtPid = 0x1FFF;
- printf("n ExtractDlPmtPidFromPat: %x ", readPtr[0] * 256 + readPtr[1]);
- while(dataLength > 0)
- {
- #ifdef OTA_TEST1
- if((readPtr[0] * 256 + readPtr[1]) == 0x0064)
- #else
- if((readPtr[0] * 256 + readPtr[1]) == _pManuDlLinkage->service_id)
- #endif
- {
- pmtPid = (UInt16)(((UInt16)readPtr[2] & 0x1f) * 256 + (UInt16)readPtr[3]);
- return pmtPid;
- }
- readPtr += 4;
- dataLength -= 4;
- }
- return pmtPid;
- }
- static void FePara(UInt32 SaveLoad)
- {
- //0:Save, 1: Load
- UInt8 writeData[14];
- UInt32 Freq, Symb, Qam;
- UInt32 dlpid;
- UInt32 i;
- for(i=0;i<14;i++) writeData[i]=0xFF;
- #ifdef OTA_TEST1
- _dlFreq = 315000000;
- _dlSymb = 6875000;
- _dlQam = 3;
- _dlPid = 128;
- #endif
- Freq = _dlFreq/1000;
- Symb = _dlSymb/1000;
- Qam = _dlQam;
- dlpid = _dlPid;
- if(SaveLoad==0)
- {
- printf("n[Upgrade_NVM_WriteData]:nOTAFre=%ld _dlSymb=%ld",_dlFreq,_dlSymb);
- //频率的转换
- writeData[0]=(Freq>>24)&0xff;
- writeData[1]=(Freq>>16)&0xff;
- writeData[2]=(Freq>>8)&0xff;
- writeData[3]=Freq&0xff;
-
- printf("nn--writeData[0]=%x",writeData[0]);
- printf("n--writeData[1]=%x",writeData[1]);
- printf("n--writeData[2]=%x",writeData[2]);
- printf("n--writeData[3]=%x",writeData[3]);
- //end
- //符号率的转换
- writeData[4]=(Symb>>24)&0xff;
- writeData[5]=(Symb>>16)&0xff;
- writeData[6]=(Symb>>8)&0xff;
- writeData[7]=Symb&0xff;
- printf("nn--writeData[4]=%x",writeData[4]);
- printf("n--writeData[5]=%x",writeData[5]);
- printf("n--writeData[6]=%x",writeData[6]);
- printf("n--writeData[7]=%x",writeData[7]);
- //end
- writeData[8]=Qam+3;
- writeData[9]=(dlpid>>8)&0xff;
- writeData[10]=dlpid&0xff;
- writeData[12]=0x01;
- writeData[13]=0x00;
- #if 1
- printf("n --[loader params]: %d, %d, %d, %x addr=0x%xn", Freq, Symb, Qam, dlpid, KB_NVM_UPDATE_BASE_ADDR);
-
- #endif
- if(KB_E2PWrite(KB_NVM_UPDATE_BASE_ADDR, writeData, 14, NULL)!=Ret_OK)
- {
- printf("n Save OTA parameter error!");
- }
- #if 1
- {
- unsigned char flag[14];
- KB_E2PRead((UINT32)KB_NVM_UPDATE_BASE_ADDR, (UINT8 *)flag, (UINT32)14, NULL);
- printf("n 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",flag[0],flag[1],flag[2],flag[3],flag[4],flag[5],flag[6],flag[7]);
- printf("n 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",flag[8],flag[9],flag[10],flag[11],flag[12],flag[13]);
- }
- #endif
-
- KB_OSPTaskDelay(500);
- }
- }
- static int KB_Parse_OTAStream(unsigned short ppid, TF_STREAM_PARA *DC_para)
- {
- unsigned char *allsectionbuf;
- int result;
- unsigned short DSI_Enable;
- result = 1;
- allsectionbuf=_bakDSISection;
- //result=DTV_GetTable(ppid,0x3b,0xff,(unsigned char **)&allsectionbuf,2);
- /* If table detected then process data */
- if (result == 1)
- {
- DSI_Enable= (UInt16)(allsectionbuf[10] << 8) & 0xff00;
- DSI_Enable|= (UInt16)allsectionbuf[11] & 0xff;
- if(DSI_Enable==0x1006)
- {
- //制造商ID
- DC_para->manufacturer_code= (UInt32)(allsectionbuf[61] << 16) & 0xff0000;
- DC_para->manufacturer_code|= (UInt32)(allsectionbuf[62] <<8) & 0xff00;
- DC_para->manufacturer_code|= (UInt32)(allsectionbuf[63] & 0xff);
-
- //硬件模式
- DC_para->hw_batch_no= (UInt16)(allsectionbuf[64]<<8) & 0xff00;
- DC_para->hw_batch_no|=(UInt16)allsectionbuf[65] & 0xff;
-
- //硬件版本
- DC_para->major_hw_version= (UInt8)allsectionbuf[66];
- DC_para->minor_hw_version=(UInt8)allsectionbuf[67] ;
-
- //软件版本
- DC_para->major_sw_version= (UInt8)allsectionbuf[77];
- DC_para->minor_sw_version|=(UInt8)allsectionbuf[78] ;
- }
-
- }
- else
- printf("rnNo OTA found.rn");
- return result;
- }
- static int StbStreamPara_Compare(unsigned short pid)
- {
- TF_STREAM_PARA stream_para;
- printf("n --------[StbStreamPara_Compare]--------------");
- memset(&stream_para,0x00,sizeof(TF_STREAM_PARA));
- KB_Parse_OTAStream(pid, &stream_para);
-
-
- #if 1
- printf("n----------StbStreamPara_Compare start--------------");
- printf("n manufacturer_code=%x", stream_para.manufacturer_code);
- printf("n major_hw_version=%x", stream_para.major_hw_version);
- printf("n minor_hw_version=%x", stream_para.minor_hw_version);
- printf("n hw_batch_no=%x", stream_para.hw_batch_no);
- printf("n major_sw_version=%x", stream_para.major_sw_version);
- printf("n major_sw_version=%x", stream_para.minor_sw_version);
- printf("n----------StbStreamPara_Compare end--------------");
- #endif
-
- if(stream_para.manufacturer_code!=gKBloaderPara.KB_MANUFACTURER_ID)
- {
- return -1;
- }
- if(stream_para.major_hw_version!=gKBloaderPara.KB_HARDWARE_MAJOR_VERSION_NUMBER
- ||stream_para.minor_hw_version!=gKBloaderPara.KB_HARDWARE_MINOR_VERSION_NUMBER)
- {
- return -2;
- }
- if(stream_para.hw_batch_no==0)
- {
- printf("n do not concern batch_no");
- }
- else
- {
- if(stream_para.hw_batch_no!=gKBloaderPara.KB_HARDWARE_BATCH_NO)
- return -3;
- }
- if(stream_para.major_sw_version!=_pManuDlLinkage->major_sw_version||stream_para.minor_sw_version!=_pManuDlLinkage->minor_sw_version)
- {
- return -4;
- }
- return 1;
- }
- void setDownloadTrigerFlag(BOOL flag)
- {
- _bDownloadTrigger = flag;
- }
- //
- // MSG_BeginDownloadSearching
- //
- int KB_BeginDownloadSearching(void)
- {
- UInt32 Freq, Symb, Qam;
- KB_OSPMsgNode MsgCaClient;
- unsigned long preFreq;
-
- printf("rn -[MSG_BeginDownloadSearching]-: _bDownloadTrigger=%d",_bDownloadTrigger);
- if(!_bDownloadTrigger)
- KB_KEY_SetReceive(0);
- //预先保存频点 shriek
- preFreq = KB_GetDTVCHN_Freq(KB_GetCurCHNTsID());
- OSA_wait(2000);
- SetLockOTAStartFlag(True);
- MSG_RemainTimeDisplay(30, True);
- //关闭播放
- LockPlayPgm();
- KB_AV_PlayStop();
- DTV_EPG_StopLastProg();
- KB_QAM_Stop();
- //BQ_EPG_DispNowNextInfoClear();
- //close filters of OTA
- KB_UpdateCheckClear();
-
- OSA_wait(1000);
- MSG_RemainTimeDisplay(29, True);
-
- OTA_CLIENT_GetDLTuneParams(&Freq, &Symb, &Qam);
-
- if(KB_CHN_SetQam(Freq, Symb, Qam)==0)
- {
- printf("rn setQam :(%ld , %ld , %ld) ok !", Freq, Symb, Qam);
- OSA_wait(1000);
- MSG_RemainTimeDisplay(28, True);
- OSA_wait(1000);
- MSG_RemainTimeDisplay(27, True);
-
- MsgCaClient.Word1 = E_DOWNLOAD_SEARCHING;
- MsgCaClient.Word2 = FALSE;
- OTA_CLIENT_Service (&MsgCaClient);
- return 0;
- }
- else
- {
- //KB_restoreCurfre(preFreq);
- printf("rn can't setqam :(%ld , %ld , %ld) ",Freq, Symb, Qam);
- KB_Timer_Stop(_lDownloadTimer);
- OSA_wait(200);
- KB_ErrorMsg(IRD_DL_SVC_FAIL);
-
- return -1;
- }
-
- return 0;
- }
- void KB_UpdateCheckClear(void)
- {
- KB_OSPMsgNode MsgCaClient;
- printf("n KB_UpdateCheckClear");
- MsgCaClient.Word1 = E_CURRENT_TS_DEASSOCIATED;
- MsgCaClient.Word2 = FALSE;
- OTA_CLIENT_Service (&MsgCaClient);
-
- return;
- }
- //input _bakBatSection
- //output _lIrdetoLinkageNum & _astIrdetoLinkage
- static void ExtraceTFLinkage(void)
- {
- UInt8 * readPtr;
- Int32 descriptor_length, bouquet_descriptors_length;
- Bool bIrdeto;
- TF_Linkage_Descriptor * pTF;
- UInt8 * tempPtr;
- Int32 tempLength;
- UInt16 ts_id, net_id, svc_id;
- UInt8 linkage_type;
- UInt8 desTag,desLen;
- //UInt8 download_time = 0xffff;
-
- readPtr = _bakBatSection;
- readPtr += 8;
-
- //bouquet_descriptors_length
- bouquet_descriptors_length = (readPtr[0] & 0x0f)*256 + readPtr[1];
- readPtr += 2;
-
- _lTFLinkageNum = 0;
- bIrdeto = False;
- //同方私有数据
- while(bouquet_descriptors_length > 0)
- {
- desTag=readPtr[0];
- desLen=readPtr[1];
- if(desTag==0x5F)
- {
- if(readPtr[2]==0x00&&readPtr[3]==0x00&&
- readPtr[4]==0x0f&&readPtr[5]==0xf8)
- {
- bIrdeto = True;
- break;
- }
- }
- readPtr+=2;
- bouquet_descriptors_length-=2;
- readPtr+=desLen;
- bouquet_descriptors_length-=desLen;
- }
- //modified by xia 06/11/21 end
-
- if(bIrdeto == False) return;
- #if 1 //for debug
- readPtr = _bakBatSection;
- readPtr += 3;
- //printf("nbouquet_id=0x%04x",readPtr[0]*256+readPtr[1]);
- #endif //debug only
-
- readPtr = _bakBatSection;
- readPtr += 8;
- bouquet_descriptors_length = (readPtr[0] & 0x0f)*256 + readPtr[1];
- readPtr += 2;
- while(bouquet_descriptors_length > 0)
- {
- //printf("nndescriptor tag = %x.", readPtr[0]);
- descriptor_length = readPtr[1];
- //printf("------descriptor descriptor_length = %d字节.", descriptor_length);
- if(readPtr[0] == 0x4A) //linkage descriptor
- {
- tempPtr = readPtr;
- tempLength = descriptor_length;
-
- ts_id = readPtr[2] * 256 + readPtr[3];
- net_id = readPtr[4] * 256 + readPtr[5];
- svc_id = readPtr[6] * 256 + readPtr[7];
- linkage_type = readPtr[8];
- tempPtr += 9;
- tempLength -= 7;
- #if 0 //debug by shriek
- printf("n[huqs]: transport_stream_id = %x.", ts_id);
- printf("n[huqs]: net_id = %x.", net_id);
- printf("n[huqs]: service_id = %x.", svc_id);
- printf("n[huqs]: linkage_type = %x.", linkage_type);
- printf("n[huqs]: tempLength = %x.", tempLength);
- #endif
- if(linkage_type == 0x82 && _lTFLinkageNum < MAX_IRDETO_LINKAGES)
- {
- while(tempLength > 0)
- {
- pTF = &(_astTFLinkage[_lTFLinkageNum]);
- pTF->transport_stream_id = ts_id;
- pTF->original_network_id = net_id;
- pTF->service_id = svc_id;
- pTF->linkage_type = 0x82;
- pTF->manufacturer_code = tempPtr[1]*256 + tempPtr[2];
- pTF->control_byte_1 = tempPtr[4];
- pTF->major_hw_version = tempPtr[6]*256 + tempPtr[7];
- pTF->minor_hw_version = tempPtr[9]*256 + tempPtr[10];
- pTF->hw_batch_no = tempPtr[12]*256 + tempPtr[13];
- pTF->major_sw_version = tempPtr[17]*256 + tempPtr[18];
- pTF->minor_sw_version = tempPtr[20]*256 + tempPtr[21];
- pTF->stb_type = tempPtr[23];
- pTF->region_code_start = tempPtr[25]*256 + tempPtr[26];
- pTF->region_code_end = tempPtr[28]*256 + tempPtr[29];
- pTF->upgrage_type = tempPtr[33];
-
- pTF->stb_sequence_start= tempPtr[35]*256*256*256 + tempPtr[36]*256*256 + tempPtr[37]*256 + tempPtr[38];
- pTF->stb_sequence_end = tempPtr[40]*256*256*256 + tempPtr[41]*256*256 + tempPtr[42]*256 + tempPtr[43];
- pTF->time = tempPtr[45];
- pTF->control_byte_2 = tempPtr[47];
- //printf("n---linkage_type:0x82 manufacturer_code=%x, hardware_code=%x, --", pTF->manufacturer_code,pTF->hardware_code);
- tempPtr += 48;
- tempLength -= 48;
-
- //record only linkage concern with this box
- #ifdef OTA_TEST
- if(pTF->manufacturer_code == 0x45)
- _lTFLinkageNum ++;
- #else
- if(pTF->manufacturer_code == gKBloaderPara.KB_MANUFACTURER_ID)
- _lTFLinkageNum ++;
- #endif
- }
- }
- // printf("linkage type is 0x80n");
- }
-
- readPtr += 2;
- bouquet_descriptors_length -= 2;
- readPtr += descriptor_length;
- bouquet_descriptors_length -= descriptor_length;
- }
- // dataLength -= bouquet_descriptors_length;
- #if 1 //debug
- printf("nn_lIrdetoLinkageNum = %d.n", _lTFLinkageNum);
- for(tempLength = 0; tempLength < _lTFLinkageNum; tempLength ++)
- {
- printf("--------------------------n");
- pTF = &(_astTFLinkage[tempLength]);
- printf(" transport_stream_id = %x.n", pTF->transport_stream_id);
- printf(" original_network_id = %x.n", pTF->original_network_id);
- printf(" service_id = %x.n", pTF->service_id);
- printf(" linkage_type = %x.n", pTF->linkage_type);
- printf(" manufacturer_code = %x.n", pTF->manufacturer_code);
- printf(" control_type_1 = %x.n", pTF->control_byte_1);
- printf(" major_hw_version = %x.n", pTF->major_hw_version);
- printf(" minor_hw_version = %x.n", pTF->minor_hw_version);
- printf(" hw_batch_no = %x.n", pTF->hw_batch_no);
- printf(" major_sw_version = %x.n", pTF->major_sw_version);
- printf(" minor_sw_version = %x.n", pTF->minor_sw_version);
- printf(" stb_type = %x.n", pTF->stb_type);
- printf(" region_code_start = %x.n", pTF->region_code_start);
- printf(" region_code_end = %x.n", pTF->region_code_end);
- printf(" upgrage_type = %x.n", pTF->upgrage_type);
- printf(" stb_sequence_start = %x.n", pTF->stb_sequence_start);
- printf(" stb_sequence_end = %x.n", pTF->stb_sequence_end);
- printf(" time = %x.n", pTF->time);
- printf(" control_byte_2 = %x.n", pTF->control_byte_2);
-
- }
- #endif
- }
- static void ExtractManuDlLinkage(void)
- {
- UInt32 i, j;
- TF_Linkage_Descriptor * pTF;
- UInt16 twobyte;
- Bool valid_load_sequence;
- #if 0
- _pManuDlLinkage = NULL;
- for(i = 0; i < _lTFLinkageNum; i ++)
- {
- pTF = &(_astTFLinkage[i]);
- if( pTF->major_hw_version== gKBloaderPara.KB_HARDWARE_MAJOR_VERSION_NUMBER
- &&pTF->linkage_type == 0x82)
- break;
- }
- printf("n[ExtractManuDlLinkage1]:hardware_code=%d, IRD_HARDWARE_VERSION_NUMBER=%d",pTF->minor_hw_version, gKBloaderPara.KB_HARDWARE_MAJOR_VERSION_NUMBER);
- for(j = 0; j < _lTFLinkageNum; j ++)
- {
- pTF = &(_astTFLinkage[j]);
- if(pTF->load_sequence_number!=0)
- {
- #ifdef OTA_TEST
- if(pTF->load_sequence_number>=gKBloaderPara.LOAD_SEQUENCE_NUMBER)
- {
- valid_load_sequence = True;
- gKBloaderPara.LOAD_SEQUENCE_NUMBER = pTF->load_sequence_number;
- }
- else
- valid_load_sequence = False;
- #else
- if(pTF->load_sequence_number>gKBloaderPara.LOAD_SEQUENCE_NUMBER)
- {
- valid_load_sequence = True;
- gKBloaderPara.LOAD_SEQUENCE_NUMBER = pTF->load_sequence_number;
- }
- else
- valid_load_sequence = False;
- #endif
- }
- else if(pTF->load_sequence_number==0)
- {
- if(gKBloaderPara.LOAD_SEQUENCE_NUMBER!=1)
- {
- valid_load_sequence = True;
- gKBloaderPara.LOAD_SEQUENCE_NUMBER = 1;
- }
- else
- valid_load_sequence = False;
- }
- twobyte = pTF->major_hw_version* 256 + pTF->minor_hw_version;
- printf("n valid_load_sequence=%d", valid_load_sequence);
- #ifdef OTA_TEST
- if( pTF->hardware_code == 0
- && pTF->linkage_type == 0x82
- && valid_load_sequence )
- {
- _pManuDlLinkage = pTF;
- break;
- }
- #else
- if( pTF->hardware_code == gKBloaderPara.KB_HARDWARE_VERSION_NUMBER
- && pTF->linkage_type == 0x82
- && valid_load_sequence )
- {
- _pManuDlLinkage = pTF;
- break;
- }
- #endif
- }
-
- if(j >= _lTFLinkageNum)
- return;
- #endif
-
- }
- static void ExtractManuDlLinkageEx(void)
- {
- UInt32 j;
- TF_Linkage_Descriptor * pTF;
- UInt32 fourbyte_bat, fourbyte_stb;
- Bool valid_load_sequence;
- unsigned long region_code;
- _pManuDlLinkage = NULL;
- for(j = 0; j < _lTFLinkageNum; j ++)
- {
- pTF = &(_astTFLinkage[j]);
- #ifdef OTA_TEST
- if(pTF->manufacturer_code==0x45
- &&pTF->major_hw_version== 0x0001
- &&pTF->minor_hw_version== 0x0001
- &&pTF->hw_batch_no==0x0001
- &&pTF->stb_type==0x01)
- {
- valid_load_sequence=True;
- }
- else
- valid_load_sequence=False;
- #else
- if( pTF->manufacturer_code==gKBloaderPara.KB_MANUFACTURER_ID
- &&pTF->major_hw_version== gKBloaderPara.KB_HARDWARE_MAJOR_VERSION_NUMBER
- &&pTF->minor_hw_version== gKBloaderPara.KB_HARDWARE_MINOR_VERSION_NUMBER
- &&pTF->hw_batch_no==gKBloaderPara.KB_HARDWARE_BATCH_NO
- &&pTF->stb_type==gKBloaderPara.kB_KeY_TYPE)
- {
-
- #ifdef OTA_SWITCH_OPEN
- if(pTF->region_code_start==0||pTF->region_code_end==0)
- {
- valid_load_sequence=True;
- }
- else
- {
- region_code = KB_GetRegion_Code();
- printf("n ------region_code = %ld", region_code);
- if(region_code>=pTF->region_code_start&®ion_code<=pTF->region_code_end)
- {
- valid_load_sequence=True;
- }
- else
- {
- valid_load_sequence=False;
- }
- }
- #else
- valid_load_sequence = True;
- #endif
- }
- else
- valid_load_sequence = False;
- #endif
- fourbyte_bat =(UInt32)(pTF->major_sw_version*256*256 + pTF->minor_sw_version);
- fourbyte_stb= (UInt32)(gKBloaderPara.KB_SOFTWARE_MAJOR_VERSION_NUMBER*256*256 + gKBloaderPara.KB_SOFTWARE_MINOR_VERSION_NUMBER);
-
- printf("n valid_load_sequence=%dn fourbyte_bat=%ld fourbyte_stb=%ld", valid_load_sequence, fourbyte_bat, fourbyte_stb);
-
- #ifdef OTA_TEST2
-
- if(valid_load_sequence)
- {
- _pManuDlLinkage = pTF;
- break;
- }
- #else
- if(valid_load_sequence)
- {
- if(pTF->control_byte_1== 0xA2)
- {
- if(fourbyte_stb<fourbyte_bat)
- {
- _pManuDlLinkage = pTF;
- break;
- }
- }
- else if(pTF->control_byte_1== 0xA4)
- {
- if(fourbyte_stb>fourbyte_bat)
- {
- _pManuDlLinkage = pTF;
- break;
- }
- }
- else if(pTF->control_byte_1== 0xA8)
- {
- if(fourbyte_stb!=fourbyte_bat)
- {
- _pManuDlLinkage = pTF;
- break;
- }
- }
- }
- #endif
- }
-
- if(j >= _lTFLinkageNum)
- return;
-
- }
- /*************************************************************************************
- Function name: GetUpgradeType
- Description: 获取升级类型
- Input: TF_Linkage_Descriptor * pManuDlLinkage,
- Output: None
- Return: upgrade type
- *************************************************************************************/
- int GetUpgradeType(TF_Linkage_Descriptor * pManuDlLinkage)
- {
- int OTA_Type = OTA_INVALID;
-
- if(pManuDlLinkage->upgrage_type==0x22) /* 1 */
- {
- OTA_Type = OTA_MANUL;
- }
- else if(pManuDlLinkage->upgrage_type==0x26) /* 2 */
- {
- OTA_Type = OTA_USER_CONFORMED;
- }
- else if(pManuDlLinkage->upgrage_type==0x2e) /* 3 */
- {
- OTA_Type = OTA_FORCED;
- }
- else if(pManuDlLinkage->upgrage_type==0x42) /* 4 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_MANUL;
- }
- else if(pManuDlLinkage->upgrage_type==0x46) /* 5 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_USER_CONFORMED;
- }
- else if(pManuDlLinkage->upgrage_type==0x4E) /* 6 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_FORCED;
- }
- else if(pManuDlLinkage->upgrage_type==0x82) /* 7 */
- {
- if((gKBloaderPara.STB_SERIAL_NO<pManuDlLinkage->stb_sequence_start)||(gKBloaderPara.STB_SERIAL_NO>pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_MANUL;
- }
- else if(pManuDlLinkage->upgrage_type==0x86) /* 8 */
- {
- if((gKBloaderPara.STB_SERIAL_NO<pManuDlLinkage->stb_sequence_start)||(gKBloaderPara.STB_SERIAL_NO>pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_USER_CONFORMED;
- }
- else if(pManuDlLinkage->upgrage_type==0x8e) /* 9 */
- {
- if((gKBloaderPara.STB_SERIAL_NO<pManuDlLinkage->stb_sequence_start)||(gKBloaderPara.STB_SERIAL_NO>pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_FORCED;
- }
- else if(pManuDlLinkage->upgrage_type==0xa6) /* 10 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_USER_CONFORMED;
- else
- OTA_Type = OTA_MANUL;
- }
- else if(pManuDlLinkage->upgrage_type==0xae) /* 11 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_FORCED;
- else
- OTA_Type = OTA_MANUL;
- }
- else if(pManuDlLinkage->upgrage_type==0xc2) /* 12 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_MANUL;
- else
- OTA_Type = OTA_USER_CONFORMED;
- }
- else if(pManuDlLinkage->upgrage_type==0xce) /* 13 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_FORCED;
- else
- OTA_Type = OTA_USER_CONFORMED;
- }
- else if(pManuDlLinkage->upgrage_type==0xe2) /* 14 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_MANUL;
- else
- OTA_Type = OTA_FORCED;
- }
- else if(pManuDlLinkage->upgrage_type==0xee) /* 15 */
- {
- if((gKBloaderPara.STB_SERIAL_NO>=pManuDlLinkage->stb_sequence_start)&&(gKBloaderPara.STB_SERIAL_NO<=pManuDlLinkage->stb_sequence_end))
- OTA_Type = OTA_USER_CONFORMED;
- else
- OTA_Type = OTA_FORCED;
- }
- return OTA_Type;
-
- }
- void OTA_test1(void)
- {
- int nres;
- nres = StbStreamPara_Compare(0x80);
- printf("n res=%d", nres);
- if(nres>0)
- {
- printf("n StbStreamPara_Compare>0, ok");
- }
- else
- {
- printf("n StbStreamPara_Compare<0, error, res=%d", nres);
- if(nres==-1||nres==-2||nres==-3)
- KB_ErrorMsg(IRD_DL_PARA1_NOT_EQUAL);
- else if(nres==-4)
- KB_ErrorMsg(IRD_DL_PARA2_NOT_EQUAL);
- OSA_wait(200);
-
- }
- }
- //True - Enable dl button, False - Disable dl button
- unsigned char OTA_CLIENT_GetDownloadState(void)
- {
- if(_bCurrentBatValid == False) //bat valid is false
- {
- printf("n--==_bCurrentBatValid == False==--n");
- return 0;
- }
- if(_pManuDlLinkage == NULL)
- {
- Print("n--==_pManuDlLinkage == NULL==--n");
- return 0;
- }
- else if(_pManuDlLinkage->control_byte_2 == 0)
- return 1;
- else if(_pManuDlLinkage->control_byte_2 == 2
- && _flag_Download_Allowed == TRUE)
- return 2;
- else
- {
- printf("n--==_pManuDlLinkage->control_byte == %d, _flag_Download_Allowed=%d==--n", _pManuDlLinkage->control_byte_2, _flag_Download_Allowed);
- return 0;
- }
-
- }
- /******************************************************************************
- Function name: KB_Flash_lc_MSGBox
- Description: local connection of flash message box
- Input: None
- Output: None
- Return: None
- ******************************************************************************/
- int KB_Flash_lc_MSGBox(char *str)
- {
- KB_OSPMsgNode Msg;
- int status;
- int ret;
- if(str==NULL)
- {
- ota_message.flag = 0;
- kb_machblue_movie_play(kb_movie_menu_otahint);
- while(1)
- {
- status = KB_OSPMsgGet(_OtaQueue, KB_Wait, 0, &Msg);
- if(status != Ret_OK)
- {
- continue;
- }
- switch (Msg.Word1)
- {
- case 1:
- printf("n 1 received!");
- ret = IDOK;
- return ret;
- case 0:
- printf("n 0 received!");
- ret = IDNO;
- return ret;
-
- default:
- printf("n else received!");
- break;
- }
- }
- }
- else
- {
- ota_message.flag = 1;
- strcpy(ota_message.ota_hint_message, str);
- KB_MB_lc_OTA_hint_2_movie(ota_message.ota_hint_message);
- }
- return ret;
-
- }
- /******************************************************************************
- Function name: KB_Flash_lc_MSGBox_Close
- Description: close local connection of flash message box
- Input: None
- Output: None
- Return: None
- ******************************************************************************/
- void KB_Flash_lc_MSGBox_Close(void)
- {
- printf("n ---------KB_Flash_lc_MSGBox_Close---------------- ");
- kb_machblue_movie_close(TRUE);
- }
- //-----------------------------------
- //----------