Class: Mifare::Ultralight

Inherits:
PICC
  • Object
show all
Defined in:
lib/mifare/ultralight.rb

Constant Summary collapse

CMD_READ =

Reads 4 pages(16 bytes) from the PICC.

0x30
CMD_WRITE =

Writes 1 page(4 bytes) to the PICC.

0xA2
CMD_3DES_AUTH =

Ultralight C 3DES Authentication.

0x1A

Instance Attribute Summary

Attributes inherited from PICC

#sak, #uid

Instance Method Summary collapse

Methods inherited from PICC

#halt, #resume_communication

Constructor Details

#initialize(pcd, uid, sak) ⇒ Ultralight

Returns a new instance of Ultralight.



7
8
9
10
11
12
13
14
15
16
# File 'lib/mifare/ultralight.rb', line 7

def initialize(pcd, uid, sak)
  super
  @model_c = false

  # Check if Ultralight C
  if support_3des_auth?
    extend UltralightC
    @model_c = true
  end
end

Instance Method Details

#model_c?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/mifare/ultralight.rb', line 35

def model_c?
  @model_c
end

#read(block_addr) ⇒ Object



18
19
20
21
22
# File 'lib/mifare/ultralight.rb', line 18

def read(block_addr)
  buffer = [CMD_READ, block_addr]

  @pcd.picc_transceive(buffer)
end

#write(page, send_data) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/mifare/ultralight.rb', line 24

def write(page, send_data)
  if send_data.size != 4
    raise UnexpectedDataError, "Expect 4 bytes data, got: #{send_data.size} byte"
  end

  buffer = [CMD_WRITE, page]
  buffer.concat(send_data)

  @pcd.picc_transceive(buffer)
end