1 /** 2 * --------- 3 * |.##> <##.| Open Smart Card Development Platform (www.openscdp.org) 4 * |# #| 5 * |# #| Copyright (c) 1999-2006 CardContact Software & System Consulting 6 * |'##> <##'| Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de) 7 * --------- 8 * 9 * This file is part of OpenSCDP. 10 * 11 * OpenSCDP is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License version 2 as 13 * published by the Free Software Foundation. 14 * 15 * OpenSCDP is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with OpenSCDP; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 * 24 * @fileoverview Example to initialize an NDEF application directory on a Mifare 1K card 25 */ 26 27 load("mifare.js"); 28 29 30 var card = new Card(_scsh3.reader); 31 32 card.reset(Card.RESET_COLD); 33 34 var mif = new Mifare(card); 35 36 print("UID: " + mif.getUID()); 37 38 if (_scsh3.reader.substr(0, 3) != "SCM") { 39 var keyaid = 0x00; // Use for ACR and Omnikey readers 40 } else { 41 print("SCM Reader detected."); 42 var keyaid = 0x60; // Use for SCS SDI 010 and 011 43 } 44 45 var key = new ByteString("FFFFFFFFFFFF", HEX); 46 mif.loadKey(keyaid, key); 47 48 49 var s = mif.newSector(0); 50 s.setKeyId(keyaid); 51 s.readAll(Mifare.KEY_A); 52 print(s.toString()); 53 54 s.setKeyA(new ByteString("A0A1A2A3A4A5", HEX)); 55 s.setKeyB(new ByteString("B0B1B2B3B4B5", HEX)); 56 s.setHeaderDataByte(new ByteString("C1", HEX)); 57 58 s.setACforBlock(1, Sector.AC_UPDATEKEYB); 59 s.setACforBlock(2, Sector.AC_UPDATEKEYB); 60 s.setACforBlock(3, Sector.AC_UPDATE_WITH_KEYB); 61 62 var mad = new ByteString("0103E103E103E103E103E103E103E103E103E103E103E103E103E103E103E1", HEX); 63 var crc = Mifare.crc8(mad); 64 var mad = ByteString.valueOf(crc,1).concat(mad); 65 66 s.update(1, mad.bytes(0, 16)); 67 s.update(2, mad.bytes(16, 16)); 68 s.update(3); 69 70 print(s.toString()); 71 72 var empty = new ByteString("00000000000000000000000000000000", HEX); 73 var ndef = new ByteString("030CD1010855016E66632E636F6DFE00", HEX); 74 75 //var ndef = new ByteString("0000030CD1010855016E66632E636F6D", HEX); 76 77 for (var i = 1; i < 2; i++) { 78 var s = mif.newSector(i); 79 s.setKeyId(keyaid); 80 s.readAll(Mifare.KEY_A); 81 //print(s.toString()); 82 83 s.setKeyA(new ByteString("D3F7D3F7D3F7", HEX)); 84 s.setKeyB(new ByteString("B0B1B2B3B4B5", HEX)); 85 s.setHeaderDataByte(new ByteString("40", HEX)); //muss laut spec auf 0x40 stehen 86 87 s.setACforBlock(0, Sector.AC_UPDATEKEYB); 88 s.setACforBlock(1, Sector.AC_UPDATEKEYB); 89 s.setACforBlock(2, Sector.AC_UPDATEKEYB); 90 s.setACforBlock(3, Sector.AC_UPDATE_WITH_KEYB); 91 92 s.update(0, ndef); 93 s.update(1, empty); 94 s.update(2, empty); 95 s.update(3); 96 97 print(s.toString()); 98 } 99