Logo Search packages:      
Sourcecode: u3-tool version File versions

int u3_read_device_property ( u3_handle_t device,
uint16_t  property_id,
uint8_t *  buffer,
uint16_t  buffer_length 
)

Read device property page

This reads a page of device properties from the device. A requested page is stored, including there page header, in 'buffer'. If the buffer size, as specified by 'buffer_length', is to small to store the whole page, only the first 'buffer_length' bytes are stored. The caller should check if the full page fitted into the buffer, by comparing the page length in the header with the buffer length. If the function returns successfull then atleast sizeof(struct property_header) bytes will be valid in the buffer, therefore 'buffer_length should be atleast 6 byte. If a property page does not excist, this function will fail.

Parameters:
device U3 device handle
property_id The index of the requested property page
buffer The buffer to return the requested property page in.
buffer_length The allocated length of 'buffer' in bytes.
Returns:
U3_SUCCESS if successful, else U3_FAILURE and an error string can be obtained using u3_error()
See also:
'struct property_header', 'struct property_*'

Definition at line 77 of file u3_commands.c.

References property_header::id, property_header::length, packed, and u3_send_cmd().

{
      uint8_t status;
      uint8_t cmd[U3_CMD_LEN] = {
            0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00
      };
      struct _write_cmd_t {
            uint8_t      scsi_opcode;
            uint16_t command;
            uint16_t id;
            uint16_t length;
            uint16_t unknown1;
            uint8_t unknown2;
      } __attribute__ ((packed)) *property_command;
      struct property_header *hdr;


      if (buffer_length < 6) {
            u3_set_error(device, "buffer supplied to "
                        "u3_read_device_property() is to small");
            return U3_FAILURE;
      }

      // First read header to prevent reading to much data
      hdr = (struct property_header *) buffer;
      property_command = (struct _write_cmd_t *) &cmd;
      property_command->id = property_id;
      property_command->length = sizeof(struct property_header);

      if (u3_send_cmd(device, cmd, U3_DATA_FROM_DEV, property_command->length,
            buffer, &status) != U3_SUCCESS)
      {
            return U3_FAILURE;
      }

      if (status != 0) {
            u3_set_error(device, "Header of property 0x%.4X could not be "
                  "read.", property_id);
            return U3_FAILURE;
      }

      if (hdr->length < sizeof(struct property_header)) {
            u3_set_error(device, "Header of property 0x%.4X indicates a "
                  "length of smaller then the header size. (len = %u)"
                  , property_id, hdr->length);
            return U3_FAILURE;
      }

      // Read full property
      if (hdr->length > buffer_length) {
            property_command->length = buffer_length;
      } else {
            property_command->length = hdr->length;
      }

      if (u3_send_cmd(device, cmd, U3_DATA_FROM_DEV, property_command->length,
            buffer, &status) != U3_SUCCESS)
      {
            return U3_FAILURE;
      }

      if (status != 0) {
            u3_set_error(device, "Property 0x%.4X could not be read.",
                  property_id);
            return U3_FAILURE;
      }

      return U3_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index