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

int u3_enable_security ( u3_handle_t device,
const char *  password 
)

Enable device security

This sets a password on the data partition.

Parameters:
device U3 device handle
password The password for the private zone
Returns:
U3_SUCCESS if successful, else U3_FAILURE and an error string can be obtained using u3_error()

Definition at line 425 of file u3_commands.c.

References packed, dpart_info::total_size, and u3_send_cmd().

                                                                  {
      uint8_t status;
      uint8_t cmd[U3_CMD_LEN] = {
            0xff, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00
      };
      struct {
            uint32_t size;
            uint8_t  hash[U3_PASSWORD_HASH_LEN];
      } __attribute__ ((packed)) data;
      struct dpart_info dp_info;
      uint32_t secure_zone_size;

      // determine size
//TODO: allow user to determine secure zone size... However currently we don't
// understand why disable security only works on a fully secured partition...
      if (u3_data_partition_info(device, &dp_info) != U3_SUCCESS) {
            u3_prepend_error(device, "Failed reading data partition info");
            return U3_FAILURE;
      }
      secure_zone_size = dp_info.total_size;

      if (secure_zone_size != 0) {
            if (u3_security_sector_round(device, round_up,
                        &secure_zone_size) != U3_SUCCESS)
            {
                  u3_prepend_error(device,
                        "Failed rounding secure zone sectors");
                  return U3_FAILURE;
            }
      }

      // fill command data
      data.size = secure_zone_size;
      u3_pass_to_hash(password, data.hash);

      if (u3_send_cmd(device, cmd, U3_DATA_TO_DEV, sizeof(data),
            (uint8_t *) &data, &status) != U3_SUCCESS)
      {
            return U3_FAILURE;
      }

      if (status != 0) {
            u3_set_error(device, "Device reported command failed: status %d", status);
            return U3_FAILURE;
      }

      return U3_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index