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

📄 cphs_mod.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	sprintf(debug, "SIM Error code!!!%d", simShrdPrm.atb[table_id].errCode);
  TRACE_EVENT(debug);
  switch (simShrdPrm.atb[table_id].reqDataFld)
  {
    case SIM_CPHS_MBXN: /* mailbox numbers */
      if ( simShrdPrm.atb[table_id].errCode EQ SIM_NO_ERROR )
      {
        cphs_data->mbNum.result = SIMOP_WRITE_OK;
        //cphs_sign_exec(E_CPHS_SET_VC_NUM, &result);
      }
      else
      {
        Cphs_write_eeprom_mailbox(cphs_data->vcEntry);
      }
      break;

    default:
      break;
  }
  simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
}

/*
+--------------------------------------------------------------------------+
|         MODULE  : CPHS standalone module                 |
| STATE   : code                        ROUTINE : Cphs_read_first_info_num |
+--------------------------------------------------------------------------+

  PURPOSE : Read first record of information numbers

*/

void Cphs_read_first_info_num(SHORT table_id)
{
  //UBYTE*        pData;         /* points to data buffer    */
  UBYTE         dataLen;

  TRACE_FUNCTION ("Cphs_read_first_info_num()");

  if ( simShrdPrm.atb[table_id].errCode NEQ SIM_NO_ERROR ) /* VO patch 040501 - remove dataLen and pData check */
  {
    if (cphs_data->simStatus EQ SIMOP_READ_OK) /* Read entry of information numbers */
    {
      cphs_data->simStatus = SIMOP_UNKNOWN;
      cphs_data->infoEntry->result = SIMOP_READ_ERR;
      if (cphs_data->InfoNumberCB != NULL)
      	(cphs_data->InfoNumberCB)(NULL, cphs_data->infoEntry);

    }
    else
    {// if we are here then its possible the read of 7F20 6F19 failed.
     // so we must try reading 7F10 EA01 instead.

     if (cphs_data->cphsPrevRead EQ SIM_CPHS_INFN)
     {
      if (!Cphs_read_sim_rcd(SIM_CPHS_INFN2, 1, 0))
      {
        cphs_data->infoEntry->result = SIMOP_READ_ERR;
        if (cphs_data->InfoNumberCB != NULL)
        	(cphs_data->InfoNumberCB)(NULL, cphs_data->infoEntry);
      }
      else
      {
        cphs_data->cphsPrevRead = SIM_CPHS_INFN2;
      }
     }
    else
    { if (cphs_data->InfoNumberListCB != NULL)
     	(cphs_data->InfoNumberListCB)(cphs_data->numList, NULL);
    }
    }
  }
  else
  {
    cphs_data->maxRec = simShrdPrm.atb[table_id].recMax;
    dataLen = simShrdPrm.atb[table_id].dataLen;

    if (cphs_data->simStatus EQ SIMOP_READ_OK) /* Read entry of information numbers */
    {
      /* VO patch 040501 - add dataLen check: if (patch) else ...  */
      if (dataLen < CPHS_MIN_INS_SIZE )
      {
        cphs_data->simStatus = SIMOP_UNKNOWN;
        cphs_data->infoEntry->result = SIMOP_READ_ERR;
      }
      else
        Cphs_req_info_num_read(cphs_data->startIdx, dataLen);
    }
    else /* Read list of information numbers */
    {
      /* VO patch 040501 - add dataLen check: if (patch) else ...  */
      if (dataLen >= CPHS_MIN_INS_SIZE )
      {
        if (cphs_data->idxLevel EQ 1) /* read this entry */
          Cphs_read_info_num(table_id);
        else    /* read the startIndex record */
          Cphs_req_info_num_read(cphs_data->startIdx, dataLen);
      }
    }
  }
}
T_PHB_NPI cvtNpi(T_ACI_TOA_NPI npi)
{
    switch (npi)
	{
    case NPI_NotPresent:
    case NPI_Unknown:       return CPHS_NPI_UNKNOWN;
    case NPI_IsdnTelephony: return CPHS_NPI_ISDN;
    case NPI_Data:          return CPHS_NPI_DATA;
    case NPI_Telex:         return CPHS_NPI_TELEX;
    case NPI_Private:       return CPHS_NPI_PRIVATE;
    case NPI_National:      return CPHS_NPI_NATIONAL;
    case NPI_ERMES:         return CPHS_NPI_M_ERMES;
    case NPI_CTS:           return CPHS_NPI_M_CTS;
		default:				        return npi;
	}
}
/*
+---------------------------------------------------------------------+
|         MODULE  : CPHS standalone module            |
| STATE   : code                        ROUTINE : Cphs_read_info_num  |
+---------------------------------------------------------------------+

  PURPOSE : Read first record of information numbers

*/

void Cphs_read_info_num(SHORT table_id)
{
  UBYTE*        pData;         /* points to data buffer    */
  UBYTE         dataLen;
  UBYTE         alphaLen;
  UBYTE         recNr;
  T_ACI_TOA     type;

  TRACE_FUNCTION ("Cphs_read_info_num()");

  pData   = simShrdPrm.atb[table_id].exchData;
  dataLen = simShrdPrm.atb[table_id].dataLen;
  recNr   = simShrdPrm.atb[table_id].recNr;

  if ( simShrdPrm.atb[table_id].errCode NEQ SIM_NO_ERROR  OR
       pData EQ NULL                                      OR
       dataLen   <  CPHS_MIN_INS_SIZE                    )
  {
    if (cphs_data->simStatus EQ SIMOP_READ_OK) /* Read entry of information numbers */
    {
      cphs_data->simStatus = SIMOP_UNKNOWN;
      cphs_data->infoEntry->result = SIMOP_READ_ERR;
      TRACE_EVENT("Info num read error");
       if (cphs_data->InfoNumberCB != NULL)
      		(cphs_data->InfoNumberCB)(NULL, cphs_data->infoEntry);

    }
    else
    {// if we are here then its possible the read of 7F20 6F19 failed.
     // so we must try reading 7F10 EA01 instead.

     if (cphs_data->cphsPrevRead EQ SIM_CPHS_INFN2)
     {
      if (!Cphs_read_sim_rcd(SIM_CPHS_INFN2, 1, 0))
      {
        cphs_data->infoEntry->result = SIMOP_READ_ERR;
         if (cphs_data->InfoNumberCB != NULL)
        		(cphs_data->InfoNumberCB)(NULL, cphs_data->infoEntry);
      }
      else
      {
        cphs_data->cphsPrevRead = SIM_CPHS_INFN2;
      }
     }
     else
     { 	if (cphs_data->InfoNumberListCB != NULL)
     		(cphs_data->InfoNumberListCB)(cphs_data->numList, NULL);
     }
    }
  	(cphs_data->InfoNumberListCB)(cphs_data->numList, NULL);
  }
  else
  {
    if (cphs_data->simStatus EQ SIMOP_READ_OK)
    {
      /* Read entry of information numbers */
      alphaLen = *pData;
      if (alphaLen)
      {
        /* copy/encode entry */
        cphs_data->infoEntry->index   = recNr;
        cphs_data->infoEntry->entryStat = *(pData + 1);

        cmhPHB_getMfwTagNt(pData + 2, alphaLen,
                          cphs_data->infoEntry->alpha.data, &cphs_data->infoEntry->alpha.len);

        pData += alphaLen + 2;

        if (*pData NEQ 0xFF)
        {
          cmhPHB_getAdrStr ( (CHAR *)cphs_data->infoEntry->number,
                             3,          /* length of number */
                             pData + 2,
                             *pData );
          cmhPHB_toaDmrg ( *( pData + 1 ), &type );
          cphs_data->infoEntry->ton = cvtTon(type.ton);
          cphs_data->infoEntry->npi = cvtNpi(type.npi);
          cphs_data->infoEntry->entryStat = cphs_data->infoEntry->entryStat | 0x80;
        }
        else
        {
          cphs_data->infoEntry->number[0] = '\0';
          cphs_data->infoEntry->ton       = CPHS_TON_UNKNOWN;
          cphs_data->infoEntry->npi       = CPHS_NPI_UNKNOWN;
        }
      }
      cphs_data->infoEntry->result = SIMOP_READ_OK;
      if (cphs_data->InfoNumberCB != NULL)
      	(cphs_data->InfoNumberCB)((T_CPHS_INFO_NUM_LIST*)NULL, cphs_data->infoEntry);
      return;
    }

    else if ((*(pData + 1) & 0x0F) > cphs_data->idxLevel)
    {
      /* This is not wished index level. Read the next */
      recNr++;
      Cphs_req_info_num_read(recNr, dataLen);
    }
    else
    {
      /* This is the wished index level. Read it. */
      alphaLen = *pData;
      if (alphaLen)      /* check alpha length */
      {
        /* copy/encode this entry in list */
        cphs_data->numList->level = cphs_data->idxLevel;
        cphs_data->numList->entry[cphs_data->numList->count].index   = recNr;
        cphs_data->numList->entry[cphs_data->numList->count].entryStat = *(pData + 1) & 0x7F;   /* set bit 8 to 0 */

        cmhPHB_getMfwTagNt(pData + 2, alphaLen,
                           cphs_data->numList->entry[cphs_data->numList->count].alpha.data,
                           &cphs_data->numList->entry[cphs_data->numList->count].alpha.len);

        pData += alphaLen + 2;

        if (*pData NEQ 0xFF)
        {
          cphs_data->numList->entry[cphs_data->numList->count].entryStat = cphs_data->numList->entry[cphs_data->numList->count].entryStat | 0x80;
        }
        cphs_data->numList->count++;
      }
      recNr++;
      /* Read the next record */
      Cphs_req_info_num_read(recNr, dataLen);
    }
  }
}


/*
+------------------------------------------------------------------------+
| MODULE  : CPHS standalone module               						|
| STATE   : code                        ROUTINE : Cphs_req_info_num_read |
+------------------------------------------------------------------------+

  PURPOSE : Read customer service profile

*/

void Cphs_req_info_num_read(UBYTE rcd_num, UBYTE dataLen)
{
  TRACE_FUNCTION ("Cphs_req_info_num_read()");

  if (rcd_num > cphs_data->maxRec)
  {  if (cphs_data->InfoNumberListCB != NULL)
  		(cphs_data->InfoNumberListCB)(cphs_data->numList, (T_CPHS_INFO_NUM_ENTRY*) NULL);

  	return;
  	}
  else
  {
    if (cphs_data->cphsPrevRead EQ SIM_CPHS_INFN)
    {
      if (Cphs_read_sim_rcd(SIM_CPHS_INFN, rcd_num, dataLen))
      {

        cphs_data->cphsPrevRead = SIM_CPHS_INFN;
      }
    }
    else
    {
      if (cphs_data->cphsPrevRead EQ SIM_CPHS_INFN2)
      {
        if (!Cphs_read_sim_rcd(SIM_CPHS_INFN2, rcd_num, dataLen))
        	 if (cphs_data->InfoNumberListCB != NULL)
				(cphs_data->InfoNumberListCB)(cphs_data->numList, (T_CPHS_INFO_NUM_ENTRY*) NULL);
        else
        {
          cphs_data->cphsPrevRead = SIM_CPHS_INFN2;
        }
      }
    }
  }
}

/*
+----------------------------------------------------------------------+
|          MODULE: CPHS standalone module               |
| STATE  : code                         ROUTINE: Cphs_build_mbn_data   |
+----------------------------------------------------------------------+


   PURPOSE :   Build mailbox number data in SIM format.

*/

void Cphs_build_mbn_data(UBYTE *data, UBYTE len)
{
  UBYTE     alphaLen;
  UBYTE     numLen;
  UBYTE     *pNumber;
  UBYTE     i, j;

  TRACE_FUNCTION ("Cphs_build_mbn_data()");

  memset(data, MFW_INVALID_SIM_DATA, len);

  /* alpha data */
  if (len <= CPHS_MIN_MBN_SIZE)
    alphaLen = 0;
  else
    alphaLen = len - CPHS_MIN_MBN_SIZE;
  i = MINIMUM (alphaLen, cphs_data->vcEntry->alpha.len);

  for ( j = 0; j < i; j++ )
    data[j] = cphs_data->vcEntry->alpha.data[j];

  data += alphaLen;

  /* number data and TON/NPI data */
  if ( cphs_data->vcEntry->number[0] EQ '+' )
  {
    cphs_data->vcEntry->ton = TON_International;
    pNumber  = &cphs_data->vcEntry->number[1];
  }
  else
    pNumber  = &cphs_data->vcEntry->number[0];

  cmhPHB_getAdrBcd ( data + 2, &numLen,
                     PHB_MAX_LEN, (CHAR *)pNumber );
  *data      = numLen + 1;
  *(data + 1) = ((( cphs_data->vcEntry -> ton << 4 ) & 0xF0 ) + ( cphs_data->vcEntry -> npi & 0x0F )) | 0x80;

  data += 12;

  /* capability/configuration identifier data and EXT identifier data */
  *data      = 0xFF;
  *(data + 1) = 0xFF;
}

/*
+--------------------------------------------------------------------------+
|         MODULE  : CPHS standalone module                 |
| STATE   : code                        ROUTINE : Cphs_read_eeprom_mailbox |
+--------------------------------------------------------------------------+

  PURPOSE : Read mailbox number from EEPROM

*/

void Cphs_read_eeprom_mailbox(void)
{
  U8                  version;
  EF_MBN              mbn;
  T_ACI_TOA           numTp;
  int                 i;
  USHORT              max_rcd;
TRACE_FUNCTION("Cphs_read_eeprom_mailbox()");
  for (i=0; i<MAX_CPHS_ENTRY; i++)
  {
   //switching from PCM to FFS
    if (FFS_fread("/Mailbox_no", &mbn, sizeof(mbn)) EQ EFFS_OK)
    {
      if (mbn.len)
      {
        cphs_data->mbNum.entries[cphs_data->mbNum.count].index = i+1;
        cmhPHB_getAdrStr ( (char *)cphs_data->mbNum.entries[cphs_data->mbNum.count].number,
                           PHB_MAX_LEN - 1, mbn.mbNum, mbn.len );
        cmhPHB_getMfwTagNt ( mbn.alphId, 10,
                             cphs_data->mbNum.entries[cphs_data->mbNum.count].alpha.data,
                             &cphs_data->mbNum.entries[cphs_data->mbNum.count].alpha.len );
        cmhPHB_toaDmrg ( mbn.numTp, &numTp );
        cphs_data->mbNum.entries[cphs_data->mbNum.count].ton = cvtTon(numTp.ton);
        cphs_data->mbNum.entries[cphs_data->mbNum.count].npi = cvtNpi(numTp.npi);
        cphs_data->mbNum.entries[cphs_data->mbNum.count].service = i;
        cphs_data->mbNum.count++;
      }
    }
  }
}

/*
+---------------------------------------------------------------------------+
|         MODULE  : CPHS standalone module                  |
| STATE   : code                        ROUTINE : Cphs_write_eepr

⌨️ 快捷键说明

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