public static ReadWithoutEncryptionResponse Read(NfcF nfcf) { var targetSystemCode = new byte[2] { (byte)0x00, (byte)0x03 }; // [1] var poolingCommand = new PollingCommand(targetSystemCode); var pooolingRequest = poolingCommand.RequestPacket(); var rawPoolingResponse = nfcf.Transceive(pooolingRequest); var poolingResponse = new PoolingResponse(rawPoolingResponse); var targetIdm = poolingResponse.IDm(); var serviceCode = new byte[2] { (byte)0x0f, (byte)0x09 }; // [2] var requestServiceCommand = new RequestServiceCommand(targetIdm, serviceCode); var requestServiceRequest = requestServiceCommand.RequestPacket(); var rawRequestServiceResponse = nfcf.Transceive(requestServiceRequest); var requestServiceResponcse = new RequestServiceResponse(rawRequestServiceResponse); // [3] var requestCommandRireki = new ReadWithoutEncryptionCommandRireki(); var requestCommandPacket = requestCommandRireki.RequestPacket(targetIdm, 10); var rawReadWithoutEncryptionCommandRireki = nfcf.Transceive(requestCommandPacket); var retData = new ReadWithoutEncryptionResponse(rawReadWithoutEncryptionCommandRireki); return(retData); }
public static ReadWithoutEncryptionResponse Read(Tag tag) { var nfcf = NfcF.Get(tag); try { nfcf.Connect(); return(Read(nfcf)); } catch (Exception e) { var errText = e.Message; if (nfcf.IsConnected) { nfcf.Close(); } return(null); } }
private void ProcessActionTechDiscoveredIntent(Intent intent) { string action = intent.Action; if (action != NfcAdapter.ActionTechDiscovered) { return; } var tag = intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Android.Nfc.Tag; if (tag != null) { var subject = this.felicaReader.WhenCardFound() as Subject <IFelicaCardMedia>; NfcF nfc = NfcF.Get(tag); nfc.Connect(); subject.OnNext(new FelicaCardMediaImplementation(nfc)); } }
public void OnNewIntent(Intent intent) { var tag = (Tag)intent.GetParcelableExtra(NfcAdapter.ExtraTag); var nfc = NfcF.Get(tag); try { nfc.Timeout = 50; nfc.Connect(); subject.OnNext(new AndroidFeliCaReader(nfc)); } catch (TagLostException) { } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } }
private bool isFelicaTag(Tag tag) { bool returnVar = false; NfcF mNfcF = NfcF.Get(tag); if (mNfcF != null) { byte[] mPMm; mPMm = mNfcF.GetManufacturer(); if (mPMm[0] == 0x01 && mPMm[1] == 0x20) { returnVar = true; } else if (mPMm[0] == 0x03 && mPMm[1] == 0x32) { returnVar = true; } } return(returnVar); }
public static bool IsFelicaTag(Tag tag) { NfcF mNfcF = NfcF.Get(tag); if (mNfcF == null) { return(false); } byte[] mPMm = mNfcF.GetManufacturer(); if (mPMm == null) { return(false); } if (mPMm.Length < 2) { return(false); } return((mPMm[0] == 0x01 && mPMm[1] == 0x20) || (mPMm[0] == 0x03 && mPMm[1] == 0x32)); }
public (TagInfo?, NFCMessage) ReadInfo(Tag tag) { if (tag == null) { return(null, NFCMessage.NFC_NULL_TAG); } return(new TagInfo { Uid = tag.GetId(), Tag = tag, IsoDep = IsoDep.Get(tag), MifareClassic = MifareClassic.Get(tag), MifareUltralight = MifareUltralight.Get(tag), NfcV = NfcV.Get(tag), Ndef = Ndef.Get(tag), NdefFormatable = NdefFormatable.Get(tag), NfcA = NfcA.Get(tag), NfcB = NfcB.Get(tag), NfcF = NfcF.Get(tag), NfcBarcode = NfcBarcode.Get(tag), TechList = tag.GetTechList() }, NFCMessage.NFC_NO_ERROR); }
public FelicaCardMediaImplementation(NfcF nfc) { this.nfc = nfc; }
protected override void OnNewIntent(Intent intent) { NFCService nfcService = new NFCService(); //Tag検出されたら処理を実行 if (intent.Action == NfcAdapter.ActionTagDiscovered) { //検出データを抽出 var tag = (Tag)intent.GetParcelableExtra(NfcAdapter.ExtraTag); // var id = intent.GetByteArrayExtra(NfcAdapter.ExtraId); // var rawTagMessages = intent.GetParcelableArrayExtra(NfcAdapter.ExtraTag); // var rawMessages = intent.GetParcelableArrayExtra(NfcAdapter.ExtraNdefMessages); //接続設定、FericaはNFCFタグ var nfcf = NfcF.Get(tag); try { nfcf.Connect(); //Fericaの仕様:https://www.sony.co.jp/Products/felica/business/tech-support/st_usmnl.html //鉄道系カードのシステムコード 0003 //Polling command var packetSize = (byte)0x06; var commandCode = (byte)0x00; var systemCode = new byte[] { 0x00, 0x03 }; var requestCode = (byte)0x01; var timeSlot = (byte)0x0f; var pollingRequest = new byte[6]; pollingRequest[0] = packetSize; pollingRequest[1] = commandCode; pollingRequest[2] = systemCode[0]; pollingRequest[3] = systemCode[1]; pollingRequest[4] = requestCode; pollingRequest[5] = timeSlot; //Pollin commandの返信 var PoolingResponse = nfcf.Transceive(pollingRequest); //IDm抽出 var IDm = new byte[8]; Array.Copy(PoolingResponse, 2, IDm, 0, 8); //Service command for 属性情報 //サービスコード008bは属性情報 http://jennychan.web.fc2.com/format/suica.html#008B commandCode = 0x02; var serviceCodeNum = (byte)0x01; var serviceCode = new byte[2] { 0x8b, 0x00 }; packetSize = (Convert.ToByte(serviceCodeNum * 2 + 11)); var serviceRequest = new byte[packetSize]; serviceRequest[0] = packetSize; serviceRequest[1] = commandCode; serviceRequest[2] = IDm[0]; serviceRequest[3] = IDm[1]; serviceRequest[4] = IDm[2]; serviceRequest[5] = IDm[3]; serviceRequest[6] = IDm[4]; serviceRequest[7] = IDm[5]; serviceRequest[8] = IDm[6]; serviceRequest[9] = IDm[7]; serviceRequest[10] = serviceCodeNum; serviceRequest[11] = serviceCode[0]; serviceRequest[12] = serviceCode[1]; //Service commandの返信、読み捨て var rawServiceRequestResponse = nfcf.Transceive(serviceRequest); //サービスコマンド008bに対するRead without encryptionコマンド commandCode = 0x06; var blockNum = (byte)0x01; var blockList = new byte[2] { 0x80, 0x00 }; packetSize = Convert.ToByte(serviceCodeNum * 2 + blockNum * 2 + 12); var readWithoutEncryption = new byte[packetSize]; readWithoutEncryption[0] = packetSize; readWithoutEncryption[1] = commandCode; readWithoutEncryption[2] = IDm[0]; readWithoutEncryption[3] = IDm[1]; readWithoutEncryption[4] = IDm[2]; readWithoutEncryption[5] = IDm[3]; readWithoutEncryption[6] = IDm[4]; readWithoutEncryption[7] = IDm[5]; readWithoutEncryption[8] = IDm[6]; readWithoutEncryption[9] = IDm[7]; readWithoutEncryption[10] = serviceCodeNum; readWithoutEncryption[11] = serviceCode[0]; readWithoutEncryption[12] = serviceCode[1]; readWithoutEncryption[13] = blockNum; readWithoutEncryption[14] = blockList[0]; readWithoutEncryption[15] = blockList[1]; //Read without encryptionコマンドの返信、返信データは後ろの16byte分 //16byteの内訳 http://jennychan.web.fc2.com/format/suica.html#008B var data = nfcf.Transceive(readWithoutEncryption); //受信データをresDataにセット nfcService.setresData(data, data.Length); nfcf.Close(); } catch { Toast.MakeText(Application.Context, "失敗、もう一度タッチしてください", ToastLength.Long).Show(); return; } } }
public AndroidFeliCaReader(NfcF nfc) { this.nfc = nfc; }