Codebase list python-yubico / 970fd01
Added support for programming NDEF slot 2 (fixes #23) Dain Nilsson 8 years ago
2 changed file(s) with 18 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
102102 def have_shifted_1_mode(self):
103103 return self.default_answer
104104
105 def have_nfc_ndef(self):
105 def have_nfc_ndef(self, slot=1):
106106 return self.default_answer
107107
108108 def have_configuration_slot(self):
2323
2424 # commands from ykdef.h
2525 _SLOT_NDEF = 0x08 # Write YubiKey NEO NDEF
26 _SLOT_NDEF2 = 0x09 # Write YubiKey NEO NDEF for slot 2
2627 _ACC_CODE_SIZE = 6 # Size of access code to re-program device
2728 _NDEF_DATA_SIZE = 54
2829 _SLOT_DEVICE_CONFIG = 0x11 # Write YubiKey >= 3 device config
7778 (0x23, "urn:nfc:",),
7879 ]
7980
81 _NDEF_SLOTS = {
82 1: _SLOT_NDEF,
83 2: _SLOT_NDEF2
84 }
85
86
8087 class YubiKeyNEO_USBHIDError(yubico_exception.YubicoError):
8188 """ Exception raised for errors with the NEO USB HID communication. """
8289
94101 return (slot == 1)
95102 return slot in [1, 2]
96103
97 def have_nfc_ndef(self):
98 return True
104 def have_nfc_ndef(self, slot=1):
105 if self.version < (3, 0, 0):
106 return slot == 1
107 return slot in [1, 2]
99108
100109 def have_device_config(self):
101110 return self.version >= (3, 0, 0)
128137 self.version_num() <= (2, 1, 9,):
129138 self.description = 'YubiKey NEO BETA'
130139
131 def write_ndef(self, ndef):
132 """
133
134
140 def write_ndef(self, ndef, slot=1):
141 """
135142 Write an NDEF tag configuration to the YubiKey NEO.
136143 """
137 return self._write_config(ndef, _SLOT_NDEF)
144 if not self.capabilities.have_nfc_ndef(slot):
145 raise yubikey_base.YubiKeyVersionError("NDEF slot %i unsupported in YubiKey NEO %s" % (slot, self.version()))
146
147 return self._write_config(ndef, _NDEF_SLOTS[slot])
138148
139149 def init_device_config(self, **kwargs):
140150 return YubiKeyNEO_DEVICE_CONFIG(**kwargs)