Beispiel #1
0
        private RFManagementNotification NCIWaitForNotification(int timeout)
        {
            NotificationPacket packet;

            do
            {
                packet = WaitForNotification(timeout);
            }
            //if ((AnswerBuffer[0] == 0x61) || (AnswerBuffer[1] == 0x05))
            while (packet.MessageType != PacketTypeEnum.ControlNotification || packet.PacketBoundryFlag != PacketBoundryFlagEnum.CompleteMessageOrLastSegment ||
                   packet.GroupIdentifier != GroupIdentifierEnum.RFMANAGEMENT ||
                   packet.OpcodeIdentifier != (byte)OpcodeRFIdentifierEnum.RF_INTF_ACTIVATED_NTF &&
                   packet.OpcodeIdentifier != (byte)OpcodeRFIdentifierEnum.RF_DISCOVER_CMD);

            RFManagementNotification resp;

            if (packet.OpcodeIdentifier == (byte)OpcodeRFIdentifierEnum.RF_DISCOVER_CMD)
            {
                resp = new RFDiscoverNotification(PacketBoundryFlagEnum.CompleteMessageOrLastSegment);
            }
            else if (packet.OpcodeIdentifier == (byte)OpcodeRFIdentifierEnum.RF_INTF_ACTIVATED_NTF)
            {
                resp = new RFInterfaceActivationNotification(PacketBoundryFlagEnum.CompleteMessageOrLastSegment);
            }
            else
            {
                throw new Exception("Invalid OpcodeRFIdentifierEnum sequence: " + packet.OpcodeIdentifier);
            }

            resp.deserialize(packet.serialize());//TODO: to many deserialize / serialize?
            NCI_PRINT(resp.ToString());
            return(resp);
        }
Beispiel #2
0
        private RFInterfaceActivationNotification ProcessRFNotification(RFManagementNotification notification)
        {
            RFInterfaceActivationNotification nd = null;

            if (notification is RFInterfaceActivationNotification)
            {
                nd = (RFInterfaceActivationNotification)notification;
            }
            else if (notification is RFDiscoverNotification) //RF_DISCOVER_NTF
            {
                List <RFDiscoverNotification> rfdns = new List <RFDiscoverNotification>();
                RFDiscoverNotification        rfdn  = (RFDiscoverNotification)notification;
                while (rfdn.DiscoverNotificationType == DiscoverNotificationTypeEnum.MORE_TO_COME)
                {
                    rfdns.Add(rfdn);
                    rfdn = (RFDiscoverNotification)NCIWaitForNotification(100);
                }
                rfdns.Add(rfdn);

                if (rfdns.Count > 1)
                {
                    //need to choose one
                    foreach (RFDiscoverNotification r in rfdns)
                    {
                        if (r.RFProtocol == RFProtocolEnum.PROT_ISODEP)
                        {
                            rfdn = r;
                            break;
                        }
                    }
                }

                if (rfdn.RFProtocol == RFProtocolEnum.PROT_ISODEP)
                {
                    RFDiscoverSelectCommand cmd2 = new RFDiscoverSelectCommand(PacketBoundryFlagEnum.CompleteMessageOrLastSegment)
                    {
                        RFDiscoveryId = rfdn.RFDiscoveryId,
                        RFProtocol    = rfdn.RFProtocol,
                        RFInterface   = RFInterfaceEnum.INTF_ISODEP //INTF_UNDETERMINED
                    };
                    RFDiscoverSelectResponse resp = new RFDiscoverSelectResponse(PacketBoundryFlagEnum.CompleteMessageOrLastSegment);
                    SendCommand(cmd2, resp);
                    //if ((AnswerBuffer[0] == 0x41) || (AnswerBuffer[1] == 0x04) || (AnswerBuffer[3] == 0x00))
                    if (resp.MessageType != PacketTypeEnum.ControlResponse ||
                        resp.PacketBoundryFlag != PacketBoundryFlagEnum.CompleteMessageOrLastSegment ||
                        resp.GroupIdentifier != GroupIdentifierEnum.RFMANAGEMENT ||
                        resp.OpcodeIdentifier != OpcodeRFIdentifierEnum.RF_DISCOVER_SELECT_CMD ||
                        resp.Status != ReponseCode.STATUS_OK)
                    {
                        nd = (RFInterfaceActivationNotification)NCIWaitForNotification(100);
                    }
                }
                else
                {
                    throw new Exception("Invalid RFProtocol");
                }
            }
            return(nd);
        }
Beispiel #3
0
 private void DisplayCardInfo(RFInterfaceActivationNotification rfIAN)
 {
     NCI_PRINT(rfIAN.TechSpecificParam.ToString());
 }
Beispiel #4
0
        private void StartPollingLoop()
        {
            stopPollingLoop = false;
            Task.Run(() =>
            {
                while (1 == 1)
                {
                    try
                    {
                        RFManagementNotification notification;
                        try
                        {
                            notification = NCIWaitForNotification(100);
                        }
                        catch (TMLTimeoutException te)
                        {
                            if (stopPollingLoop)
                            {
                                //cardReaderHAL.Close();
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        RFInterfaceActivationNotification rfIAN = ProcessRFNotification(notification);

                        if (((byte)rfIAN.RFTechnologiesAndMode & (byte)RFModeMaskEnum.MODE_MASK) == (byte)RFModeMaskEnum.MODE_POLL)
                        {
                            if ((rfIAN.RFProtocol != RFProtocolEnum.PROT_NFCDEP) && (rfIAN.RFInterface != RFInterfaceEnum.INTF_UNDETERMINED))
                            {
                                try
                                {
                                    //NCI_PRINT("POLL MODE: Remote T{0:d}T activated", notification.RFProtocol);
                                    OnCardPutInField(EventArgs.Empty);

                                    while (hostTimeoutCounter > 0)
                                    {
                                        int delay = HOST_TIMEOUT / 5;
                                        Task.Delay(TimeSpan.FromMilliseconds(delay)).Wait();
                                        hostTimeoutCounter -= delay;
                                    }

                                    /* Process card Presence check */
                                    NCIProcessReaderMode(rfIAN.RFProtocol, NxpNciRWOperationEnum.PRESENCE_CHECK);
                                    NCI_PRINT("CARD REMOVED\n");
                                    OnCardRemovedFromField(EventArgs.Empty);
                                    /* Restart the discovery loop */
                                    NCIRestartDiscovery();
                                    ResetHostTimeOut();
                                }
                                catch (Exception ex)
                                {
                                    ResetHostTimeOut();
                                    throw ex;
                                }
                            }
                            else
                            {
                                NCI_PRINT("POLL MODE: Undetermined target\n");
                                /* Restart discovery loop */
                                NCIStopDiscovery();
                                NCIStartDiscovery();
                            }
                        }
                    }
                    catch
                    {
                        //do nothing
                    }
                }
            });
        }