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

📄 rilsimtk_ozone.cpp

📁 windows mobile RIL软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    case SIMTK_CMD_GET_ICON_DATA:
      RILRetailTrace((TEXT("RilDrv: SimToolkit Error - Unsupported command response (%i)\r\n"), lpbResponse[3 + uAddLen]));
      return E_FAIL;

    default:
      RILRetailTrace((TEXT("RilDrv: SimToolkit Error - Unknown command response (%i)\r\n"), lpbResponse[3 + uAddLen]));
      return E_FAIL;
  }

  if (!QueueCmdWithRetry(COMMAND_PORT, pHandle, szCmd, CMDOPT_NONE, APIID_SENDSIMTOOLKITCMDRESPONSE, NULL, NULL, hr, SIMTK_CMD_RETRIES, SIMTK_CMD_RETRY_DELAY, ParseRspError, this)) {
    RILRetailTrace((TEXT("RilDrv: SimToolkit Error - unable to put CCommand into the queue\r\n")));
    return E_FAIL;
  }

  return hr;
}

//////////////////////////////////////////////////////////////////////////////
//
// Send a Sim-Toolkit envelope command.
//
// Params:
//  pHandle   : Pointer to CRilInstanceHandle to be used for the operation.
//  lpbCommand: The command to send to the module.
//  dwSize    : The soze of the command.
//
// Return:
//  S_OK on successs, E_FAIL otherwise.
//
//////////////////////////////////////////////////////////////////////////////
HRESULT CSimToolkitHandling::SendEnvelopeCmd(CRilInstanceHandle* pHandle, const BYTE* lpbCommand, DWORD dwSize) {
char     szCmd[MAX_ATCMD_LEN];
UCHAR    ucStatus;
HRESULT  hr = S_OK;

  // Check the envelope command type
  switch (lpbCommand[0]) {
    case SIMTK_EVT_MENU_SELECTION:
      RILRetailTrace((TEXT("RilDrv: SimToolkit: MENU SELECTION command\r\n")));
      // Check for help request
      if ((lpbCommand[2] > 7) && ((lpbCommand[8] == 15) || (lpbCommand[8] == 95))) {
        ucStatus = 19;
      } else {
        ucStatus = 0;
      }
      // Compose the menu selection command
      sprintf(szCmd, "AT^SSTR=211,%d,%d\r", ucStatus, lpbCommand[8]);
      break;

    case SIMTK_EVT_END_SESSION:
      RILRetailTrace((TEXT("RilDrv: SimToolkit: END SESSION command\r\n")));
      // Terminate the current session
      strcpy(szCmd, "AT^SSTR=254\r");
      break;

    default:
      RILRetailTrace((TEXT("RilDrv: SimToolkit Error - unknown envelope command (0x%0.2X)\r\n"), lpbCommand[0]));
      return E_FAIL;
  }

  if (!QueueCmdWithRetry(COMMAND_PORT, pHandle, szCmd, CMDOPT_NONE, APIID_SENDSIMTOOLKITENVELOPECMD, NULL, NULL, hr, SIMTK_CMD_RETRIES, SIMTK_CMD_RETRY_DELAY)) {
    RILRetailTrace((TEXT("RilDrv: SimToolkit Error - unable to put CCommand into the queue\r\n")));
    return E_FAIL;
  }

  return hr;
}

//////////////////////////////////////////////////////////////////////////////
//
// Parsing function called to fill a structure telling our Sim-Toolkit
// capabilities.
//
// Return:
//  S_OK on successs, E_FAIL otherwise.
//
//////////////////////////////////////////////////////////////////////////////
HRESULT CSimToolkitHandling::ParseGetDevCapsNotifications(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam) {
RILSIMTOOLKITNOTIFYCAPS*  prstnc;

  pBlob = NULL;
  cbBlob = 0;

  prstnc = (RILSIMTOOLKITNOTIFYCAPS *)AllocBlob(sizeof(RILSIMTOOLKITNOTIFYCAPS));
  if (!prstnc) {
      return E_OUTOFMEMORY;
  }

  memset(prstnc, 0x00, sizeof(RILSIMTOOLKITNOTIFYCAPS));

  prstnc->cbSize               = sizeof(RILSIMTOOLKITNOTIFYCAPS);
  prstnc->dwParams             = RIL_PARAM_SIMTKN_ALL;
  prstnc->dwRefresh            = RIL_SIMTKN_RADIOIMPLEMENTS_NONOTIFICATION;
  prstnc->dwMoreTime           = RIL_SIMTKN_RADIOIMPLEMENTS_NONOTIFICATION;
  prstnc->dwPollInterval       = RIL_SIMTKN_RADIOIMPLEMENTS_NONOTIFICATION;
  prstnc->dwPollingOff         = RIL_SIMTKN_RADIOIMPLEMENTS_NONOTIFICATION;
  prstnc->dwSetUpCall          = RIL_SIMTKN_MEIMPLEMENTS;
  prstnc->dwSendSS             = RIL_SIMTKN_RADIOIMPLEMENTS_NONOTIFICATION;
  prstnc->dwSendUSSD           = RIL_SIMTKN_RADIOIMPLEMENTS_NONOTIFICATION;
  prstnc->dwSendSMS            = RIL_SIMTKN_RADIOIMPLEMENTS_NONOTIFICATION;
  prstnc->dwPlayTone           = RIL_SIMTKN_MEIMPLEMENTS;
  prstnc->dwDisplayText        = RIL_SIMTKN_MEIMPLEMENTS;
  prstnc->dwGetInkey           = RIL_SIMTKN_MEIMPLEMENTS;
  prstnc->dwGetInput           = RIL_SIMTKN_MEIMPLEMENTS;
  prstnc->dwSelectItem         = RIL_SIMTKN_MEIMPLEMENTS;
  prstnc->dwSetupMenu          = RIL_SIMTKN_MEIMPLEMENTS;
  prstnc->dwSetupIdleModeText  = RIL_SIMTKN_MEIMPLEMENTS;
  prstnc->dwLocalInfo          = RIL_SIMTKN_RADIOIMPLEMENTS_NONOTIFICATION;
  prstnc->dwNotifyFlags        = RIL_CAPS_NOTIFY_SIMTOOLKITCMD |
                                 RIL_CAPS_NOTIFY_SIMTOOLKITEVENT;

  pBlob = (void*)prstnc;
  cbBlob = sizeof(RILSIMTOOLKITNOTIFYCAPS);

  return S_OK;
}

//////////////////////////////////////////////////////////////////////////////
//
// Converts a created SAT command Hex string into binary blob format.
//
//////////////////////////////////////////////////////////////////////////////
void CSimToolkitHandling::ConvertSATBlob(char* szSATCmd, BYTE* pBlob) {
UINT  i, j, len;

  len = strlen(szSATCmd) / 2;
  for (i = 0, j = 0; j < len; j++, i += 2) {
    pBlob[j] = SemiByteCharsToByte(szSATCmd[i], szSATCmd[i+1]);
  }
}

//////////////////////////////////////////////////////////////////////////////
//
// Converts a UCS2 string into ASCII format.
//
//////////////////////////////////////////////////////////////////////////////
void CSimToolkitHandling::ConvertSATString(char* lpszSATString) {
UINT  i, j, len, w;
char  c;

  len = strlen(lpszSATString) / 2;
  for (i = 0, j = 0; i < len; i += 2, j += 4) {
    sscanf(&(lpszSATString[j]), "%04X", &w);
    if (!UnicodeCharToGSM((WCHAR)w, &c)) {
      c = '*';
    }
    sprintf(&(lpszSATString[i]), "%0.2X", c);
  }
}

//////////////////////////////////////////////////////////////////////////////
//
// Converts a UCS2 phone number into a BCD coded address.
//
//////////////////////////////////////////////////////////////////////////////
void CSimToolkitHandling::ConvertSATAddress(char* lpszSATString) {
UINT  i, j, len, c;

  len = strlen(lpszSATString);
  for (i = 0, j = 0; i < len; i += 4) {
    sscanf(&(lpszSATString[i]), "%04X", &c);
    switch (c) {
      case '+':
        ADD_DIGIT(lpszSATString, j, '0');
        ADD_DIGIT(lpszSATString, j, '0');
        break;
      case '*':
        ADD_DIGIT(lpszSATString, j, 'A');
        break;
      case '#':
        ADD_DIGIT(lpszSATString, j, 'B');
        break;
      default:
        ADD_DIGIT(lpszSATString, j, SemiByteToChar((char)((c - '0') & 0x0F), FALSE));
        break;
    }
  }
}

//////////////////////////////////////////////////////////////////////////////
//
// Convert the text info of the alpha field to GSM if the string is too long,
// add the length info.
//
// Return:
//  TRUE if the length was valid, FALSE if it was greater than 255.
//
//////////////////////////////////////////////////////////////////////////////
BOOL CSimToolkitHandling::UpdateTextField(char* szSATText, BOOL fUseGSM) {
  if (fUseGSM || ((strlen(szSATText) - SIMTK_TXT_STANDARD_SIZE) > SIMTK_TXT_MAX_SIZE)) {
    // Convert the text field from UCS2 to GSM and update format field
    ConvertSATString(szSATText + SIMTK_TXT_STANDARD_SIZE);
    szSATText[5] = '4';
  }
  return AddSATCmdLength(szSATText);
}

//////////////////////////////////////////////////////////////////////////////
//
// Convert the text info of the alpha field to GSM if the string is too long,
// add the length info.
//
// Return:
//   TRUE if the length was valid, FALSE if it was greater than 255.
//
//////////////////////////////////////////////////////////////////////////////
BOOL CSimToolkitHandling::UpdateAlphaField(char* szSATText, BOOL fUseGSM) {
UINT  i, len;

  len = strlen(szSATText);
  if (fUseGSM || ((len - SIMTK_TXT_ALPHA_SIZE) > SIMTK_TXT_MAX_SIZE)) {
    // We have to remove the UCS2 flag -> shift the string accordingly
    for (i = SIMTK_TXT_ALPHA_SIZE; i <= len; i++) {
      szSATText[i-2] = szSATText[i];
    }
    // Now convert the text field from UCS2 to GSM
    ConvertSATString(szSATText + SIMTK_TXT_ALPHA_SIZE - 2);
  }
  return AddSATCmdLength(szSATText);
}

//////////////////////////////////////////////////////////////////////////////
//
// Add item number, convert the text info of the alpha field to GSM if the
// string is too long, add the length info.
//
// Return:
//  TRUE if the length was valid, FALSE if it was greater than 255.
//
//////////////////////////////////////////////////////////////////////////////
BOOL CSimToolkitHandling::UpdateItemField(char* szSATText, UINT nItem, BOOL fUseGSM) {
UINT  i, len;
char  szBuf[3];

  len = strlen(szSATText);
  sprintf(szBuf, "%0.2X", nItem);
  if (fUseGSM || ((len - SIMTK_TXT_ITEM_SIZE) > SIMTK_TXT_MAX_SIZE)) {
    // We have to remove the UCS2 flag -> shift the string accordingly
    for (i = SIMTK_TXT_ITEM_SIZE; i <= len; i++) {
      szSATText[i-2] = szSATText[i];
    }
    // Now convert the text field from UCS2 to GSM
    ConvertSATString(szSATText + SIMTK_TXT_ITEM_SIZE - 2);
  }

  // Add item number
  szSATText[4] = szBuf[0];
  szSATText[5] = szBuf[1];

  return AddSATCmdLength(szSATText);
}

//////////////////////////////////////////////////////////////////////////////
//
// Add the the correct length field to the given SAT string.
//
// Return:
//  TRUE if the length was valid, FALSE if it was greater than 255.
//
//////////////////////////////////////////////////////////////////////////////
BOOL CSimToolkitHandling::AddSATCmdLength(char* szSATCmd) {
UINT  i, len;
char  szBuf[3];

  len = strlen(szSATCmd);
  if (len > ((2 * 255) + 4)) {
    return FALSE;
  }
  sprintf(szBuf, "%0.2X", ((len - 4) / 2));
  if (len > ((2 * 127) + 4)) {
    // We have to add additional byte to length information
    // First shift the whole string
    for (i = (len + 2); i > 3; i--) {
      szSATCmd[i] = szSATCmd[i-2];
    }
    // Now add the length information
    szSATCmd[2] = '8';
    szSATCmd[3] = '1';
    szSATCmd[4] = szBuf[0];
    szSATCmd[5] = szBuf[1];
  } else {
    // Just add the length information
    szSATCmd[2] = szBuf[0];
    szSATCmd[3] = szBuf[1];
  }
  return TRUE;
}

//////////////////////////////////////////////////////////////////////////////
//
// Create and send the blob corresponding to the Sim-Toolkit command.
//
// Params:
//  dwNotificationCode: The blob notification code
//  pBlob             : The storage for the blob (out)
//  cbBlob            : The size of the blob (out)
//  szCmd             : The SAT command to be sent
//
// Return:
//  TRUE on successs, FALSE otherwise.
//
//////////////////////////////////////////////////////////////////////////////
BOOL CSimToolkitHandling::HandleBlob(DWORD dwNotificationCode, void*& pBlob, UINT& cbBlob, char* szCmd) {
  // Allocate the blob
  cbBlob = strlen(szCmd) / 2;
  pBlob = AllocBlob(cbBlob);
  if (!pBlob) {
    cbBlob = 0;
    return FALSE;
  }

  ConvertSATBlob(szCmd, (BYTE*)pBlob);

  // Trace blob data
  TraceBlob((BYTE*)pBlob, cbBlob);

  // Notify the SIM manager of the SAT command
  return m_pRilDevice->BroadcastRealBlobNotification(dwNotificationCode, pBlob, cbBlob);
}

⌨️ 快捷键说明

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