setAuthConfig method

Future<void> setAuthConfig({
  1. required int startingBlock,
  2. required AuthLock lock,
})

Sets the authentication configuration on a Mifare Ultralight C RFID tag.

This method updates the RFID tag's authentication configuration, including the starting block for authentication operations and the lock status, based on the provided parameters. It writes this configuration to the tag, ensuring that future authentication actions adhere to these settings.

Parameters

  • startingBlock: The block number at which authentication operations should start.
  • lock: The AuthLock status indicating whether the tag is locked for writing, reading, or both. This is determined by the AuthLock enum value provided.

Throws

  • RFIDException if there's an error during the write operation. This could result from issues like communication problems with the RFID reader or invalid block numbers that fall outside the tag's memory range.

Example

try {
  await card.setAuthConfig(startingBlock: 4, lock: AuthLock.readWrite);
  print('Authentication configuration set successfully');
} catch (e) {
  print('Failed to set authentication configuration: $e');
}

Note: Properly configuring the authentication settings is crucial for the security and integrity of the RFID tag's data. This method allows for precise control over these parameters, aiding in the secure management of the tag.

Implementation

Future<void> setAuthConfig({
  required int startingBlock,
  required AuthLock lock,
}) async {
  _validateBlockNumber(
    blockNumber: startingBlock,
    start: OTP_ADDRESS,
    end: MEMORY_ADDRESS_END,
  );

  try {
    await reader.writeBlock(blockNumber: AUTH_CONFIG_ADDRESS_START, data: [
      startingBlock,
      0x00,
      0x00,
      0x00,
    ]);

    await reader
        .writeBlock(blockNumber: AUTH_CONFIG_ADDRESS_START + 1, data: [
      lock.value,
      0x00,
      0x00,
      0x00,
    ]);
  } catch (e) {
    throw RFIDException('Error setting authentication configuration');
  }
}