⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctcaldat.c

📁 free sources for gsm
💻 C
📖 第 1 页 / 共 5 页
字号:
Caveats:
*/
static void CTShowIMEI( void )
   {
   UINT16 i;
   STRING s1 = GSM_NEW_STRING( 55 );   /* collect string for output to CT window */
   STRING ctout = s1;
   UINT8 tempGLIMEISV[8];

   /* Copy the scrambled IMEI into a buffer and get it descrambled */
   GSMmemcpy( tempGLIMEISV, CalDataPtr->GLIMEISV, 8 );
   UHNVMDecodeIMEI( tempGLIMEISV );

   ctout += GSMsprintf( s1, "ShowIMEI:RET:" );
   ctout += GSMsprintf( ctout, "0x%02x", ( UINT8 ) tempGLIMEISV[0] );
   for ( i = 1; i < 8; i++ )
      {
      ctout += GSMsprintf( ctout, ",0x%02x", ( UINT8 ) tempGLIMEISV[i] );
      }

   GSMsprintf( ctout, "\n" );

   CTSendStringResponse( s1 );

   GSMFree( s1 );
   }
//MSL
#if defined(IMEI_SECURITY_MSL)
static void CTGetMSLAddr( void )
{
   //
   STRING sTemp = GSM_NEW_STRING( 55 );
   STRING ctout = sTemp;
   char MSLAddr[5][2];
   UINT8 bTemp = 0, bTemp2 = 0;

   //
   GSMmemcpy( MSLAddr[0], CalDataPtr->MSLAddress_0, sizeof(CalDataPtr->MSLAddress_0) );
   GSMmemcpy( MSLAddr[1], CalDataPtr->MSLAddress_1, sizeof(CalDataPtr->MSLAddress_0) );
   GSMmemcpy( MSLAddr[2], CalDataPtr->MSLAddress_2, sizeof(CalDataPtr->MSLAddress_0) );
   GSMmemcpy( MSLAddr[3], CalDataPtr->MSLAddress_3, sizeof(CalDataPtr->MSLAddress_0) );
   GSMmemcpy( MSLAddr[4], CalDataPtr->MSLAddress_4, sizeof(CalDataPtr->MSLAddress_0) );

   //
   ctout += GSMsprintf(sTemp, "MSLAddr : ");	

   for(bTemp=0; bTemp<5; bTemp++)
   {
      for(bTemp2=0; bTemp2<2; bTemp2++)
      {
         MSLAddr[bTemp][bTemp2] ^= MSL_ADDR_WEIGHT;
         
         ctout += GSMsprintf(ctout, "%02c", (UINT8)MSLAddr[bTemp][bTemp2]);
      }
   }
      
   ctout += GSMsprintf(ctout, "\nCTGetMSLAddr : Done");	

   CTSendStringResponse(sTemp);
   GSMFree(sTemp);

}

static void CTSetMSLAddr( CTTokenList * CTCmd )
{
   //
   UINT8 *pCalDataStart = NULL;
   UINT8 bTemp1 = 0, bTemp2 = 0;
   char MSLAddr[5][2];
   UINT16 FlashResult = 0;
   char *strMSLAddr = CTCmd->Token[1]; 

   //
   if ( CTCmd->NumTokens != 2 )
   {
      CTSendStringResponse( " CTSetMSLAddr : MSLAddr paramater index is not matched .. Retry \n " );   
      return;
   }

   //
   for(bTemp1=0; bTemp1<5; bTemp1++)
   {
      for(bTemp2=0; bTemp2<2; bTemp2++)
      {
         MSLAddr[bTemp1][bTemp2] = *(strMSLAddr+bTemp1*2 +bTemp2);

         if( GSMislower(MSLAddr[bTemp1][bTemp2]) )
         {
            MSLAddr[bTemp1][bTemp2] = GSMtoupper(MSLAddr[bTemp1][bTemp2]);
         }

         MSLAddr[bTemp1][bTemp2] ^= MSL_ADDR_WEIGHT;
      }
   }
   
   //
   GSMmemcpy( CalDataPtr->MSLAddress_0, MSLAddr[0], sizeof(CalDataPtr->MSLAddress_0) );
   GSMmemcpy( CalDataPtr->MSLAddress_1, MSLAddr[1], sizeof(CalDataPtr->MSLAddress_0) );
   GSMmemcpy( CalDataPtr->MSLAddress_2, MSLAddr[2], sizeof(CalDataPtr->MSLAddress_0) );
   GSMmemcpy( CalDataPtr->MSLAddress_3, MSLAddr[3], sizeof(CalDataPtr->MSLAddress_0) );
   GSMmemcpy( CalDataPtr->MSLAddress_4, MSLAddr[4], sizeof(CalDataPtr->MSLAddress_0) );
   
   //
   CTSendStringResponse( "CTSetMSLAddr : Done");
   IsSetMSLAddr = TRUE;
   
   return;
}

static void CTSetMSLCode( CTTokenList * CTCmd )
{
   //
   UINT8 MSLCode[3];
   UINT8 i = 0;
   UINT8 *pCalDataStart = NULL;
   UINT16 FlashResult = 0;
   char *strMSLCode = CTCmd->Token[1]; 
   char strTemp[3];

   GSMmemset(strTemp, NULL, sizeof(strTemp));

   //
   if ( CTCmd->NumTokens != 2 )
   {
      CTSendStringResponse( " CTSetMSLAddr : CTSetMSLCode paramater index is not matched .. Retry \n " );   
      return;
   }

   //
   if(CalDataPtr->MSLCode_0 != (0x00^MSL_CODE_WEIGHT) ||
      CalDataPtr->MSLCode_1 != (0x00^MSL_CODE_WEIGHT) ||
      CalDataPtr->MSLCode_2 != (0x00^MSL_CODE_WEIGHT)        )
   {
      CTSendStringResponse( "CTSetMSLCode : Failed (MSLCode != 000000) ");
      return;
   }

   //
   for(i=0; i<3; i++)
   {
      GSMmemcpy(strTemp, strMSLCode+i*2, 2);
      MSLCode[i] = (UINT8)GSMstrtoul(strTemp);

      MSLCode[i] ^= MSL_CODE_WEIGHT;
   }

   CalDataPtr->MSLCode_0 = MSLCode[0];
   CalDataPtr->MSLCode_1 = MSLCode[1];
   CalDataPtr->MSLCode_2 = MSLCode[2];
   
   //
   IsSetMSLCode = TRUE;
   CTSendStringResponse( "CTSetMSLCode : Done");
   return;

}


static void CTCheckMSL( CTTokenList * CTCmd )
{

   //
   UINT8 MSLCode[3];
   static UINT8 CheckCount = 0;
   UINT8 i = 0;
   char *strMSLCode = CTCmd->Token[1]; 
   char strTemp[3];
   UINT8 InputMSLCode[3];

   GSMmemset(strTemp, NULL, sizeof(strTemp));

   //
   if ( CTCmd->NumTokens != 2 )
   {
      CTSendStringResponse( " CTCheckMSL : CTCheckMSL paramater index is not matched .. Retry \n " );   
      return;
   }

   //
   for(i=0; i<3; i++)
   {
      GSMmemcpy(strTemp, strMSLCode+i*2, 2);
      InputMSLCode[i] = (UINT8)GSMstrtoul(strTemp);
   }

   //
   if(   CalDataPtr->MSLCode_0 == (0x00^MSL_CODE_WEIGHT) &&
         CalDataPtr->MSLCode_1 == (0x00^MSL_CODE_WEIGHT) &&
         CalDataPtr->MSLCode_2 == (0x00^MSL_CODE_WEIGHT)        )
   {
      CTSendStringResponse( "CTCheckMSL : TRUE ");
      return;
   }

   //
   MSLCode[0] = CalDataPtr->MSLCode_0;
   MSLCode[1] = CalDataPtr->MSLCode_1;
   MSLCode[2] = CalDataPtr->MSLCode_2;

   for ( i = 0; i < 3 ; i++ )
   {
      MSLCode[i] ^= MSL_CODE_WEIGHT;
      
      if(MSLCode[i] != InputMSLCode[i])
      {
         CTSendStringResponse( " CTCheckMSL : FALSE" );   

         CheckCount++;
         if(CheckCount == 3)
         {
            uhSystemReset();
         }
         return;
      }
   }

   IsMSLCodeRight = TRUE;
   CTSendStringResponse( " CTCheckMSL : TRUE" );   

}

#if defined(IMEI_SECURITY_DISABLE_MSL)
static void CTMakeUnvalidCal( void )
{
   //
   CALIBRATION_DATA *CalData = NULL;  
   UINT16 FlashResult = 0;

   //
   CalData = ( CALIBRATION_DATA * ) GSMMalloc( sizeof( CALIBRATION_DATA ) );
   GSMmemcpy( CalData, CalDataPtr, sizeof( CALIBRATION_DATA ) ); 

   //
   if ( HWNVMGetDataSize(  ) > CALIBRATION_SECTOR_SIZE )
      GSMprintf( "Calibration data too big !!!\n" );

   CalData->CheckSum = 0;
   FlashResult = FlashUtilWrite( ( UINT32 ) pCalDataInFlash,
                                 sizeof( CALIBRATION_DATA ),
                                 CalData,
                                 FSU_Calibration,
                                 FU_FLAG_PRESERVE | FU_FLAG_ERASE | FU_FLAG_FORCE_USE_HEAP );

   //
   #define FFS_OK 0
   
   if ( FlashResult == FFS_OK )
   {
      CTSendStringResponse( "CTMakeUnvalidCal : Done");
   }
   else
   {
      CTSendStringResponse( "CTMakeUnvalidCal : Failed (FlashUtilWrite Error)");
      GSMFree(CalData);
      return;
   }

   GSMFree(CalData);
   return;

}
#endif

#endif

/*---------------------------------------------------------------------*/
/*
Name: CTPokeHWNVM
Desc: Fills the required number of bytes ( up to 32 ) into the HW NVM area.
Params: Are trensfered via the GeneralPurposeArray
Returns:
Caveats: The parameters in the GeneralPurposeArray are (in the given
         sequence): high byte of the offset relative to the begining of
         the HW NVM Area, low byte of the offset, length, bytes to be
         poked into the area. The changed area is finaly stored by the
         command 'StoreHW'.
*/
static void CTPokeHWNVM( void )
   {
   UINT16 Offset = GeneralPurposeArray[0] * 256 + GeneralPurposeArray[1];
   UINT8 Length = GeneralPurposeArray[2];
   UINT8 *Buffer = ( UINT8 * ) & GeneralPurposeArray[3];
   BOOLEAN PokeOK;

#ifdef DEBUG
   GSMprintf( "Offset%u,Length:%u,Buffer:%u\n", Offset, Length, Buffer );
#endif

   PokeOK = HWNVMPoke( Offset, Length, Buffer );

   if ( PokeOK )
      {
      CTSendStringResponse( "PokeHWNVM:DONE\n" );
      }
   else
      {
      CTSendStringResponse( "PokeHWNVM:WRONG:OUT_OF_RANGE\n" );
      }
   }


/*---------------------------------------------------------------------*/
/*
Name: CTPrepareForIMEIBlackout
Desc: Figures out if the bytes to be 'peeked' include IMEI bytes.
Params:  Input params: The offset and size in HW data which is being peeked
         Output params: The lengths along that stretch that should be blacked out
                        if the IMEI is present in it (i.e. only filled if function returns TRUE).
Returns: TRUE if some blacking out will be needed
Caveats:
*/
static BOOLEAN CTPrepareForIMEIBlackout( UINT16 Offset, UINT16 Length, UINT16 * Start, UINT16 * End )
   {
   UINT16 IMEIOffset = HWNVMGetIMEIOffset(  );
   UINT16 IMEISize = HWNVMGetIMEISize(  );
   UINT16 IMEILastByte;
   UINT16 LastByte;

   IMEILastByte = IMEIOffset + IMEISize - 1;
   LastByte = Offset + Length - 1;

   if ( Offset >= IMEIOffset && Offset <= IMEILastByte )
      {
      /* The start of the area to be peeked at is in the IMEI range */
      *Start = 0;
      *End = ( LastByte > IMEILastByte ? IMEILastByte : LastByte ) - Offset;
      return TRUE;
      }
   else if ( LastByte >= IMEIOffset && LastByte <= IMEILastByte )
      {
      /* The end of the area to be peeked at is in the IMEI range */
      *Start = IMEIOffset - Offset;
      *End = LastByte - Offset;
      return TRUE;
      }
   else if ( Offset < IMEIOffset && LastByte > IMEILastByte )
      {

      /*
         The start of the area to be peeked at is before the IMEI range and the end of
         the area to be peeked at is after the IMEI range
      */
      *Start = IMEIOffset - Offset;
      *End = IMEILastByte - Offset;
      return TRUE;
      }
   return FALSE;
   }

/*---------------------------------------------------------------------*/
/*
Name: CTPeekHWNVM
Desc: Returns the requested number of bytes stored at the given address.
Params:
Returns:
Caveats:
We don't allow the scramled IMEI to be peeked at.
*/

static void CTPeekHWNVM( void )
   {
   UINT16 Offset = GeneralPurposeArray[0] * 256 + GeneralPurposeArray[1];
   UINT8 Length = GeneralPurposeArray[2];
   STRING s1 = GSM_NEW_STRING( 150 );  /* collect string for output to CT window */
   STRING ctout = s1;
   UINT8 *peekptr;
   UINT16 limit = HWNVMGetDataSize(  );
   UINT16 blackOutStart = 0,
         blackOutEnd = 0;
   UINT16 i;
   BOOLEAN doBlackOut;

   if ( ( Length == 0 ) || ( Offset + Length >= limit ) )
      {
      CTSendStringResponse( "PeekHWNVM:WRONG:OUT_OF_RANGE\n" );
      }

   doBlackOut = CTPrepareForIMEIBlackout( Offset, Length, &blackOutStart, &blackOutEnd );

   ctout += GSMsprintf( s1, "PeekHWNVM:RET:" );

   if ( Length > 32 )
      {
      Length = 32;
      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -