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

📄 diagdiag.c

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

RETURN VALUE
  The address of the function or NULL if the function is not found in the
  function table.

SIDE EFFECTS
  None.

===========================================================================*/
void *diag_lookup_prop
(
  char *prop_name
)
{
  int i = 0;

  if ( prop_name == NULL )
  {
    return (void *) NULL;
  }

  while ( diag_prop_table[ i ].name != NULL )
  {
    if ( strncmp(
                 diag_prop_table[ i ].name,
                 prop_name,
                 DIAG_MAX_PROPERTY_NAME_SIZE
         ) == 0 )
    {
      return diag_prop_table[ i ].address;
    }
    i++;
    if ( i >= DIAG_MAX_NUM_PROPS )
    {
      /*
      ** Will get here only if the properties table has been corrupted.
      */
      break;
    }
  }
  return (void *) NULL;
} /* diag_lookup_prop */


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

FUNCTION DIAG_GUID_IS_VALID

DESCRIPTION
  This static function returns true or false depending on whether the
  input guid (globally unique identifier) matches that of the current build.

DEPENDENCIES
  None.

RETURN VALUE
  TRUE if the input guid is valid, FALSE otherwise.

SIDE EFFECTS
  None.

===========================================================================*/
LOCAL boolean diag_guid_is_valid
(
  diag_guid_type guid
)
{
  if ( ( guid[ 0 ] == diag_guid[ 0 ] ) &&
       ( guid[ 1 ] == diag_guid[ 1 ] ) &&
       ( guid[ 2 ] == diag_guid[ 2 ] ) &&
       ( guid[ 3 ] == diag_guid[ 3 ] ) )
  {
    return TRUE;
  }
  else
  {
    return FALSE;
  }
} /* diag_guid_is_valid */

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

FUNCTION DIAGDIAG_GET_PROPERTY

DESCRIPTION
  This procedure processes a get_property request. The request packet
  specifies an address in memory and a number of bytes. The specifed number
  of bytes are retrieved starting at the specified address and returned in
  the response packet.

DEPENDENCIES
  None.

RETURN VALUE
  The length of the response packet.

SIDE EFFECTS
  None.

===========================================================================*/
PACKED void * diagdiag_get_property
(
  PACKED void *req_pkt,
  uint16 pkt_len
)
{
  DIAG_GET_PROPERTY_F_req_type *req = (DIAG_GET_PROPERTY_F_req_type *) req_pkt;
  DIAG_GET_PROPERTY_F_rsp_type *rsp;
  word rsp_len = FPOS(DIAG_GET_PROPERTY_F_rsp_type, data );

  /*----------------------------------------------------------------------
    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) );
  }

#ifdef FEATURE_DIAG_HW_ADDR_CHECK
  /*-------------------------------------------------------------------------
    Check to see if block requested is within a valid range
  --------------------------------------------------------------------------*/
  if (!hw_valid_addr ((void *) &req->guid[0], sizeof(diag_guid_type)) ) {
    MSG_ERROR("Invalid Address",0,0,0);
    return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
  }
#endif

/*----------------------------------------------------------------------------
  Allocate buffer space for response packet.
----------------------------------------------------------------------------*/
  rsp = (DIAG_GET_PROPERTY_F_rsp_type * )
    diagpkt_alloc(DIAG_GET_PROPERTY_F, MAX(rsp_len + 1, rsp_len + req->size));

/*----------------------------------------------------------------------------
  Fill in some of the fields in the response packet.
----------------------------------------------------------------------------*/
  memcpy((void *) &rsp->guid[0],
         (const void *) &req->guid[0],
         sizeof(diag_guid_type));

  rsp->address  = req->address;

/*---------------------------------------------------------------------------
  Check for valid GUID.
----------------------------------------------------------------------------*/
  if ( !diag_guid_is_valid( req->guid ) ) {
    rsp->size    = 0;
    rsp->data[0] = DIAG_EXTN_INVALID_GUID;

    /* Adjust length and return */
    diagbuf_shorten(rsp, rsp_len + 1);
    return rsp;
  }

/*---------------------------------------------------------------------------
  Check property size against maximum allowed size.
----------------------------------------------------------------------------*/
  if ( req->size > DIAG_MAX_PROPERTY_SIZE ) {
    rsp->size     = 0;
    rsp->data[0]  = DIAG_EXTN_INVALID_SIZE;

    /* Adjust length and return */
    diagbuf_shorten(rsp, rsp_len + 1);
    return rsp;
  }

  rsp->size = req->size;

/*---------------------------------------------------------------------------
  Move the memory bytes into the response buffer.  Lock out interrupts to
  preserve consistency of the memory block.
----------------------------------------------------------------------------*/
  INTLOCK( );
  memcpy((void *) rsp->data,
         (const void *) req->address,
         req->size);
  INTFREE( );

  /* Adjust length and return */
  diagbuf_shorten(rsp, rsp_len + req->size);
  return rsp;

} /* diagdiag_get_property */


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

FUNCTION DIAGDIAG_PUT_PROPERTY

DESCRIPTION
  This procedure processes a put_property request. The values specified in
  the request packet are written into memory starting at the specified
  address.

DEPENDENCIES
  None.

RETURN VALUE
  The length of the response packet.

SIDE EFFECTS
  None.

===========================================================================*/
PACKED void * diagdiag_put_property
(
  PACKED void *req_pkt, /* pointer to request packet  */
  uint16 pkt_len            /* length of request packet  */
)
{
  DIAG_PUT_PROPERTY_F_req_type *req = (DIAG_PUT_PROPERTY_F_req_type *) req_pkt;
  DIAG_PUT_PROPERTY_F_rsp_type *rsp;
  word rsp_len = FPOS(DIAG_PUT_PROPERTY_F_rsp_type, data );

  /*----------------------------------------------------------------------
    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) );
  }

#ifdef FEATURE_DIAG_HW_ADDR_CHECK
  /*-------------------------------------------------------------------------
    Check to see if block requested is within a valid range
  --------------------------------------------------------------------------*/
  if (!hw_valid_addr ((void *) &req->guid[0], sizeof(diag_guid_type)) ) {
    MSG_ERROR("Invalid Address",0,0,0);
    return( diagpkt_err_rsp(DIAG_BAD_PARM_F, req_pkt, pkt_len) );
  }
#endif

/*----------------------------------------------------------------------------
  Allocate buffer space for response packet.
----------------------------------------------------------------------------*/
  rsp = (DIAG_PUT_PROPERTY_F_rsp_type *) diagpkt_alloc (DIAG_PUT_PROPERTY_F,
                                                        rsp_len + 1);

/*----------------------------------------------------------------------------
  Fill in some of the fields in the response packet.
----------------------------------------------------------------------------*/
  memcpy((void *) &rsp->guid[0],
         (const void *) &req->guid[0],
         sizeof(diag_guid_type));

  rsp->address = req->address;

/*---------------------------------------------------------------------------
  Check for valid GUID.
----------------------------------------------------------------------------*/
  if ( !diag_guid_is_valid( req->guid ) ) {
    rsp->size    = 0;
    rsp->data[0] = DIAG_EXTN_INVALID_GUID;

    return rsp;
  }

/*---------------------------------------------------------------------------
  Check property size against maximum allowed size.
----------------------------------------------------------------------------*/
  if ( req->size > DIAG_MAX_PROPERTY_SIZE ) {
    rsp->size    = 0;
    rsp->data[0] = DIAG_EXTN_INVALID_SIZE;

    return rsp;
  }

  rsp->size = req->size;

  /*------------------------------------------------------------------------
    Transfer the bytes from the request packet into memory.  Lock out
    interrupts to ensure consistency of the write.
  -------------------------------------------------------------------------*/
  INTLOCK( );
  memcpy((void *) req->address,
         (const void *) req->data,
         req->size);
  INTFREE( );

  /* Adjust length and return */
  diagbuf_shorten(rsp, rsp_len);
  return rsp;

} /* diagdiag_put_property */


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

FUNCTION DIAGDIAG_GET_GUID

DESCRIPTION
  This procedure processes a get_guid request. The GUID (globally unique
  identifier) for this build is retrieved and returned in the response
  packet. The GUID is stored during the build process.

===========================================================================*/
PACKED void * diagdiag_get_guid
(
  PACKED void *req_pkt, /* pointer to request packet  */
  uint16 pkt_len            /* length of request packet  */
)
{
  DIAG_GET_GUID_F_rsp_type *rsp;
  const unsigned int rsp_len = sizeof (DIAG_GET_GUID_F_rsp_type);

  /*--------------------------------------------
    Allocate buffer space for response packet.
  --------------------------------------------*/
  rsp = (DIAG_GET_GUID_F_rsp_type *) diagpkt_alloc (DIAG_GET_GUID_F, rsp_len);

  memcpy((void *) &rsp->guid[0],
         (const void *) &diag_guid[0],
         sizeof(diag_guid_type));

  return rsp;

} /* diagdiag_get_guid */


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

FUNCTION DIAGDIAG_GET_PERM_PROPERTY

DESCRIPTION
  This procedure processes a get_perm_property request. The contents of
  the structure specified by name in the request packet are retrieved.

DEPENDENCIES
  None.

RETURN VALUE
  The length of the response packet.

SIDE EFFECTS
  None.

===========================================================================*/
PACKED void * diagdiag_get_perm_property
(
  PACKED void *req_pkt, /* pointer to request packet  */
  uint16 pkt_len            /* length of request packet  */
)
{
  void *prop_addr;    /* address of the specified property */
  DIAG_GET_PERM_PROPERTY_F_req_type *req =
    (DIAG_GET_PERM_PROPERTY_F_req_type *) req_pkt;
  DIAG_GET_PERM_PROPERTY_F_rsp_type *rsp;
  const unsigned int rsp_len = sizeof( DIAG_GET_PERM_PROPERTY_F_rsp_type );

/*----------------------------------------------------------------------------
  Allocate buffer space for response packet.
----------------------------------------------------------------------------*/
  rsp = (DIAG_GET_PERM_PROPERTY_F_rsp_type *)
    diagpkt_alloc (DIAG_GET_PERM_PROPERTY_F, rsp_len);

/*----------------------------------------------------------------------------
  Fill in some of the fields in the response packet.
----------------------------------------------------------------------------*/
  memcpy((void *) &rsp->guid[0],
         (const void *) &req->guid[0],
         sizeof(diag_guid_type));

  memcpy((void *) &rsp->name[0],
         (const void *) &req->name[0],
         sizeof(req->name));

/*---------------------------------------------------------------------------
  Check for valid GUID.
----------------------------------------------------------------------------*/
  if ( !diag_guid_is_valid( req->guid ) ) {
    rsp->size    = 0;
    rsp->data[0] = DIAG_EXTN_INVALID_GUID;
    return rsp;
  }

/*---------------------------------------------------------------------------
  Check data size against maximum allowed size.
----------------------------------------------------------------------------*/
  if ( req->size > DIAG_MAX_PROPERTY_SIZE ) {
    rsp->size    = 0;
    rsp->data[0] = DIAG_EXTN_INVALID_SIZE;
    return rsp;
  }

/*---------------------------------------------------------------------------
  Look up the address of the specified property. Return with an error status
  if we do not get a valid address. If we get a valid address, move the
  memory bytes into the response buffer.  Lock out interrupts to preserve
  consistency of the memory block.
----------------------------------------------------------------------------*/
  prop_addr = diag_lookup_prop( (char *) req->name );

  if ( prop_addr == NULL ) {
    rsp->size    = 0;
    rsp->data[0] = DIAG_EXTN_INVALID_NAME;
    return rsp;
  }

  rsp->size = req->size;

  INTLOCK( );
  memcpy((void *) &rsp->data[0],
         (const void *) prop_addr,
         req->size * sizeof(byte));
  INTFREE( );

  return rsp;

⌨️ 快捷键说明

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