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

📄 diagdiag.c

📁 free sources for gsm
💻 C
📖 第 1 页 / 共 5 页
字号:


/*===========================================================================

FUNCTION DIAGDIAG_POKEB

DESCRIPTION
  This procedure pokes a byte into memory and formats a poke response
  buffer.

===========================================================================*/
PACKED void * diagdiag_pokeb (
  PACKED void *req_pkt,
  uint16 pkt_len
)
{
  DIAG_POKEB_F_req_type *req = (DIAG_POKEB_F_req_type *)req_pkt;
  DIAG_POKEB_F_rsp_type *rsp;
  const int rsp_len = sizeof(DIAG_POKEB_F_rsp_type);
  int i, count;
  PACKED byte *src = NULL;
  PACKED byte *dest = NULL;

  count = req->length;
  src = &req->data[0];
  dest = req->ptr;

  /*----------------------------------------------------------------------
    Check length of request packet.
  ----------------------------------------------------------------------*/
  if (pkt_len != sizeof (DIAG_POKEB_F_req_type))
  {
    return (diagpkt_err_rsp (DIAG_BAD_LEN_F, req_pkt, pkt_len));
  }

  /*----------------------------------------------------------------------
    Check security, since this is a secure funciton
  ----------------------------------------------------------------------*/
  if (diag_get_security_state() != DIAG_SEC_UNLOCKED) {
    return( diagpkt_err_rsp(DIAG_BAD_SEC_MODE_F, req_pkt, pkt_len) );
  }

  /*----------------------------------------------------------------------
    Check block size against maximum allowable block size.
  ----------------------------------------------------------------------*/
  if (count > DIAG_MAX_POKE_B) {
    return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
  }

#ifdef FEATURE_DIAG_HW_ADDR_CHECK
  /*---------------------------------------------------------------------
    Check to see if address requested is within a valid range.
  ----------------------------------------------------------------------*/
  else if (!hw_valid_addr ((void *) dest, count * sizeof (byte))) {
    return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
  }
#endif

#ifdef FEATURE_VOC_TASK
  /*---------------------------------------------------------------------------
    The vocoder memory space is a special case since the DSP's clocks are
    turned off during sleep, making the address invalid.  Let voc handle it.
  ----------------------------------------------------------------------------*/
  if (voc_valid_addr ((void *) dest, count * sizeof (byte)))
  {
    voc_status_type eVocStatus;

    /* Since the data is byte ordered, no need to hanlde endian-ness here. */
    eVocStatus = voc_poke_cmd ((void *) dest, (void *) src,
                               count * sizeof (byte));

    if (eVocStatus != VOC_DONE_S)
    {
      return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
    }
  }
  else /* do it ourselves. */
#endif /* FEATURE_VOC_TASK */
  {
    /*----------------------------------------------------------------------
      Lock out interrupts to preserve consistency of the memory block.
    ----------------------------------------------------------------------*/
    INTLOCK ();
    for (i = 0; i < count; i++) {
       outp( dest, *src);
      dest++;
      src++;
    }
    INTFREE ();
  }

  /*-------------------------------------------------------------------------
   Prepare the response packet.
  -------------------------------------------------------------------------*/
  rsp = (DIAG_POKEB_F_rsp_type *)diagpkt_alloc(DIAG_POKEB_F, rsp_len);

  if (rsp)
  {
    *rsp = *req;
  }

  return (rsp);

} /* diagdiag_pokeb */


/*===========================================================================

FUNCTION DIAGDIAG_POKEW

DESCRIPTION
  This procedure pokes a word into memory and formats a poke response
  message.

===========================================================================*/
PACKED void * diagdiag_pokew (
  PACKED void *req_pkt,
  uint16 pkt_len
)
{
  DIAG_POKEW_F_req_type *req = (DIAG_POKEW_F_req_type *)req_pkt;
  DIAG_POKEW_F_rsp_type *rsp;
  const int rsp_len = sizeof(DIAG_POKEW_F_rsp_type);
  int i, count;
  PACKED word *src = NULL;
  PACKED word *dest = NULL;

  count = req->length;
  src = &req->data[0];
  dest = req->ptr;

  /*----------------------------------------------------------------------
    Check length of request packet.  This is critical since the download
    protocol used by QPST uses HDLC encoded packets with the equivalent
    of command code 6.  Length check is the only thing that prevents
    accidental pokes!
  ----------------------------------------------------------------------*/
  if (pkt_len != sizeof (DIAG_POKEW_F_req_type))
  {
    return (diagpkt_err_rsp (DIAG_BAD_LEN_F, req_pkt, pkt_len));
  }

  /*----------------------------------------------------------------------
    Check security, since this is a secure funciton
  ----------------------------------------------------------------------*/
  if (diag_get_security_state() != DIAG_SEC_UNLOCKED) {
    return( diagpkt_err_rsp(DIAG_BAD_SEC_MODE_F, req_pkt, pkt_len) );
  }

  /*----------------------------------------------------------------------
    Check block length against maximum allowable length.
  ----------------------------------------------------------------------*/
  if (count > DIAG_MAX_POKE_W) {
    return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
  }

#ifdef FEATURE_DIAG_HW_ADDR_CHECK
  /*----------------------------------------------------------------------
    Check to be sure the block is a valid block.
  ----------------------------------------------------------------------*/
  if (!hw_valid_addr ((void *) dest, count * sizeof (word))) {
    return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
  }
#endif

#ifdef FEATURE_VOC_TASK
  /*---------------------------------------------------------------------------
    The vocoder memory space is a special case since the DSP's clocks are
    turned off during sleep, making the address invalid.  Let voc handle it.
  ----------------------------------------------------------------------------*/
  if (voc_valid_addr ((void *) dest, count * sizeof(word)))
  {
    voc_status_type eVocStatus;

    /* Since the data is byte ordered, no need to hanlde endian-ness here. */
    eVocStatus = voc_poke_cmd((void *) dest, (void *) src,
                              count * sizeof(word));

    if (eVocStatus != VOC_DONE_S)
    {
      return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
    }
  }
  else /* do it ourselves. */
#endif /* FEATURE_VOC_TASK */
  {
    /*----------------------------------------------------------------------
      Lock out interrupts to preserve consistency of the memory block.
    ----------------------------------------------------------------------*/
    INTLOCK ();
    for (i = 0; i < count; i++) {
      outpw(dest, *src);
      dest++;
      src++;
    }
    INTFREE ();
  }

  /*----------------------------------------------------------------------
    Prepare the response packet.
  ----------------------------------------------------------------------*/
  rsp = (DIAG_POKEW_F_rsp_type *)diagpkt_alloc(DIAG_POKEW_F, rsp_len);

  if (rsp)
  {
    *rsp = *req;
  }

  return (rsp);

} /* diagdiag_pokew */



/*===========================================================================

FUNCTION DIAGDIAG_POKED

DESCRIPTION
  This procedure pokes a dword into memory and formats a poke response
  message.

===========================================================================*/
PACKED void * diagdiag_poked (
  PACKED void *req_pkt,
  uint16 pkt_len
)
{
  DIAG_POKED_F_req_type *req = (DIAG_POKED_F_req_type *)req_pkt;
  DIAG_POKED_F_rsp_type *rsp;
  const int rsp_len = sizeof(DIAG_POKED_F_rsp_type);
  int i, count;
  PACKED dword *src = NULL;
  PACKED dword *dest = NULL;

  count = req->length;
  src = &req->data[0];
  dest = req->ptr;

  /*----------------------------------------------------------------------
    Check length of request packet.
  ----------------------------------------------------------------------*/
  if (pkt_len != sizeof (DIAG_POKED_F_req_type))
  {
    return (diagpkt_err_rsp (DIAG_BAD_LEN_F, req_pkt, pkt_len));
  }

  /*----------------------------------------------------------------------
    Check security, since this is a secure funciton
  ----------------------------------------------------------------------*/
  if (diag_get_security_state() != DIAG_SEC_UNLOCKED) {
    return( diagpkt_err_rsp(DIAG_BAD_SEC_MODE_F, req_pkt, pkt_len) );
  }

  /*----------------------------------------------------------------------
    Check block length against maximum allowed length.
  ----------------------------------------------------------------------*/
  if (count > DIAG_MAX_POKE_D) {
    return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
  }

#ifdef FEATURE_DIAG_HW_ADDR_CHECK
  /*----------------------------------------------------------------------
    Check to see that requested block is a valid block.
  ----------------------------------------------------------------------*/
  if (!hw_valid_addr ((void *) dest, count * sizeof (dword)) ) {
    return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
  }
#endif

#ifdef FEATURE_VOC_TASK
  /*---------------------------------------------------------------------------
    The vocoder memory space is a special case since the DSP's clocks are
    turned off during sleep, making the address invalid.  Let voc handle it.
  ----------------------------------------------------------------------------*/
  if (voc_valid_addr ((void *) dest, count * sizeof(dword)))
  {
    voc_status_type eVocStatus;

    /* Since the data is byte ordered, no need to hanlde endian-ness here. */
    eVocStatus = voc_poke_cmd((void *) count, (void *) src,
                              count * sizeof(dword));

    if (eVocStatus != VOC_DONE_S)
    {
      return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
    }
  }
  else /* do it ourselves. */
#endif /* FEATURE_VOC_TASK */
  {
    /*----------------------------------------------------------------------
      Lock out interrupts to preserve consistency of the memory block.
    ----------------------------------------------------------------------*/
    INTLOCK ();
    for (i = 0; i < count; i++) {
      outpdw(dest, *src);
      dest++;
      src++;
    }
    INTFREE ();
  }

  /*-----------------------------------------------------------------------
   Prepare the response packet.
  -----------------------------------------------------------------------*/
  rsp = (DIAG_POKED_F_rsp_type *)diagpkt_alloc(DIAG_POKED_F, rsp_len);

  if (rsp)
  {
    *rsp = *req;
  }

  return (rsp);

} /* diagdiag_poked */



/*===========================================================================

FUNCTION DIAGDIAG_VER

DESCRIPTION
  Return the diag version

===========================================================================*/
PACKED void * diagdiag_ver (
  PACKED void *req_pkt,
  uint16 pkt_len
)
{
  DIAG_DIAG_VER_F_rsp_type *rsp;
  const int rsp_len = sizeof (DIAG_DIAG_VER_F_rsp_type);

  rsp = (DIAG_DIAG_VER_F_rsp_type *)diagpkt_alloc(DIAG_DIAG_VER_F, rsp_len);

  /*-------------------------------------------------------------------------
    Return diag source code version
  -------------------------------------------------------------------------*/
  rsp->ver = DIAG_DIAGVER;

  return (rsp);

} /* diagdiag_diag_ver */



/*===========================================================================

FUNCTION DIAGDIAG_FEATURE_QUERY

DESCRIPTION
  This procedure processes a request to query for features in the current
  build.  It returns a variable length bit mask where each bit corresponds to
  a particular feature defined in diagpkt.h in feature_query_enum_type.

============================================================================*/
PACKED void * diagdiag_feature_query (
  PACKED void *req_pkt,
  uint16 pkt_len
)
{
  DIAG_FEATURE_QUERY_F_rsp_type *rsp;
  const int rsp_len = sizeof(DIAG_FEATURE_QUERY_F_rsp_type);

  rsp =(DIAG_FEATURE_QUERY_F_rsp_type *)diagpkt_alloc(DIAG_FEATURE_QUERY_F, rsp_len);

  rsp->feature_mask_size = FEATURE_MASK_LENGTH;

  /* Copy the current mask into the diag pkt */
  memcpy( (void *) rsp->feature_mask,
          diag_feature_mask,
          FEATURE_MASK_LENGTH
        );

  /* return the size of the variable length packet.  command_code and
  ** feature_mask_size is constant.  FEATURE_MASK_LENGTH changes
  ** as more features are added
  */
  return (rsp);

} /* diagdiag_feature_query */



/*===========================================================================

FUNCTION DIAGDIAG_PASSWORD

DESCRIPTION
  Processes an entry of the Security Password.
  This function compares the password in the phone to what was sent in
  the packet.  If they are the same, the successful Security unlock is
  noted (setting the diag_get_security_state() mask to UNLOCKED), and a value of TRUE
  is returned to the external device.
  If they are NOT the same, Security remains locked, a value of FALSE is
  returned to the external device, and the phone is powered off,
  to deter hackers.

SIDE EFFECTS
  May cause the phone to power off!  (After returning from this routine).

===========================================================================*/
PACKED void * diagdiag_password (
  PACKED void *req_pkt,
  uint16 pkt_len
)
{
  DIAG_PASSWORD_F_req_type *req = (DIAG_PASSWORD_F_req_type *) req_pkt;
  DIAG_PASSWORD_F_rsp_type *rsp;
  const int rsp_len = sizeof(DIAG_PASSWORD_F_rsp_type);

⌨️ 快捷键说明

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