Example #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);
        }
Example #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);
        }