Ejemplo n.º 1
0
        /// <summary>
        /// Transceives the data of the raw format card.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="buffer">The binary data for a parameter or additional commands.</param>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the the method fails due to an invalid operation.</exception>
        public Task <byte[]> TransceiveAsync(byte[] buffer)
        {
            var task = new TaskCompletionSource <byte[]>();

            byte[] resultBuffer = null;
            Interop.Nfc.TagTransceiveCompletedCallback callback = (int result, IntPtr resultData, int dataSize, IntPtr userData) =>
            {
                if (result == (int)NfcError.None)
                {
                    resultBuffer = new byte[dataSize];
                    Marshal.Copy(resultData, resultBuffer, 0, dataSize);
                    task.SetResult(resultBuffer);
                }
                return;
            };

            int ret = Interop.Nfc.Tag.Transceive(_tagHandle, buffer, buffer.Length, callback, IntPtr.Zero);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to transceive data, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(task.Task);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves all the tag information.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <returns>The list of the NfcTagInformation objects.</returns>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public IEnumerable <NfcTagInformation> ForeachInformation()
        {
            List <NfcTagInformation> infoList = new List <NfcTagInformation>();

            Interop.Nfc.TagInformationCallback callback = (IntPtr key, IntPtr infoValue, int valueSize, IntPtr userData) =>
            {
                if (key != IntPtr.Zero && infoValue != IntPtr.Zero)
                {
                    NfcTagInformation tagInfo = new NfcTagInformation(Marshal.PtrToStringAnsi(key), new byte[valueSize]);

                    Marshal.Copy(infoValue, tagInfo.InformationValue, 0, valueSize);

                    infoList.Add(tagInfo);

                    return(true);
                }
                return(false);
            };

            int ret = Interop.Nfc.Tag.ForeachInformation(_tagHandle, callback, IntPtr.Zero);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get all Tag information, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(infoList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads the NDEF formatted data from the NFC tag.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public Task <NfcNdefMessage> ReadNdefMessageAsync()
        {
            var task = new TaskCompletionSource <NfcNdefMessage>();

            NfcNdefMessage ndefMsg = null;

            Interop.Nfc.TagReadCompletedCallback callback = (int result, IntPtr ndefMessage, IntPtr userData) =>
            {
                if (result == (int)NfcError.None)
                {
                    ndefMsg = new NfcNdefMessage(ndefMessage);
                    task.SetResult(ndefMsg);

                    return(true);
                }
                return(false);
            };

            int ret = Interop.Nfc.Tag.ReadNdef(_tagHandle, callback, IntPtr.Zero);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to read ndef message, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(task.Task);
        }
Ejemplo n.º 4
0
        internal Task SetActivationAsync(bool activation)
        {
            TaskCompletionSource <bool> task = new TaskCompletionSource <bool>();
            IntPtr id = IntPtr.Zero;

            lock (_callback_map)
            {
                id = (IntPtr)_requestId++;
                _callback_map[id] = (error, key) =>
                {
                    Log.Debug(Globals.LogTag, "nfc activated");
                    if (error != (int)NfcError.None)
                    {
                        Log.Error(Globals.LogTag, "Error occurs during Nfc activating, " + (NfcError)error);
                        task.SetException(new InvalidOperationException("Error occurs during Nfc activating, " + (NfcError)error));
                    }
                    task.SetResult(true);
                    lock (_callback_map)
                    {
                        _callback_map.Remove(key);
                    }
                };

                int ret = Interop.Nfc.SetActivation(activation, _callback_map[id], id);
                if (ret != (int)NfcError.None)
                {
                    Log.Error(Globals.LogTag, "Failed to activate nfc, Error - " + (NfcError)ret);
                    NfcErrorFactory.ThrowNfcException(ret);
                }
            }
            return(task.Task);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Unsets the application as a preferred handler.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public void UnsetPreferredApplication()
        {
            int ret = Interop.Nfc.CardEmulation.UnsetPreferredHandler();

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to unset preferred handler, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Unregisters a previously registered AID for the specified category.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="seType">The type of the secure element.</param>
        /// <param name="category">Enumeration value of the category.</param>
        /// <param name="aid">The application ID specified in the ISO/IEC 7816-4.</param>
        /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public void UnregisterAid(NfcSecureElementType seType, NfcCardEmulationCategoryType category, string aid)
        {
            int ret = Interop.Nfc.CardEmulation.UnregisterAid((int)seType, (int)category, aid);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to unregister aid, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Disables the foreground dispatch for the "EVT_TRANSACTION" to the given application.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public void DisableTransactionForegroundDispatch()
        {
            int ret = Interop.Nfc.DisableTransactionForegroundDispatch();

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to disable foreground dispatch, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Disables the card emulation mode.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public void DisableCardEmulation()
        {
            int ret = Interop.Nfc.CardEmulation.DisableCardEmulatiion();

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to disable card emulation mode, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a record with the mime type payload.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="mimeType">The mime type [RFC 2046] \(ex. text/plain, image/jpeg ). This value is stored in the type field.</param>
        /// <param name="data">The data in the form of the bytes array.</param>
        /// <param name="dataSize">The size of the data.</param>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public NfcNdefRecord(string mimeType, byte[] data, uint dataSize)
        {
            int ret = Interop.Nfc.NdefRecord.CreateMime(out _recordHandle, mimeType, data, dataSize);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to create ndef Mime record, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a record with the URI type payload.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="uri">The URI string that will be stored in the payload.</param>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public NfcNdefRecord(string uri)
        {
            int ret = Interop.Nfc.NdefRecord.CreateUri(out _recordHandle, uri);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to create ndef Uri record, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a record with the text type payload.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="text">The encoded text.</param>
        /// <param name="languageCode">The language code string value followed by the IANA [RFC 3066] \(ex: en-US, ko-KR).</param>
        /// <param name="encode">The encoding type.</param>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public NfcNdefRecord(string text, string languageCode, NfcEncodeType encode)
        {
            int ret = Interop.Nfc.NdefRecord.CreateText(out _recordHandle, text, languageCode, (int)encode);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to create ndef Text record, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a record with a given parameter value.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="format">The type name format.</param>
        /// <param name="type">The specified type name.</param>
        /// <param name="id">The record ID.</param>
        /// <param name="payload">The payload of this record.</param>
        /// <param name="paloadLength">The byte size of the payload.</param>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public NfcNdefRecord(NfcRecordTypeNameFormat format, byte[] type, byte[] id, byte[] payload, uint paloadLength)
        {
            int ret = Interop.Nfc.NdefRecord.Create(out _recordHandle, (int)format, type, type.Length, id, id.Length, payload, paloadLength);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to create Ndef record, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Sends the APDU (Application Protocol Data Unit) response to the CLF (Contactless Front-end).
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="response">The bytes array of the response data.</param>
        /// <param name="responseLength">The size of the response bytes array.</param>
        /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public void HceSendApduResponse(byte[] response, uint responseLength)
        {
            int ret = Interop.Nfc.CardEmulation.HceSendApduRespondse(_secureElementHandle, response, responseLength);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to hcd send apdu response, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates an object for the access point.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public NfcNdefMessage()
        {
            int ret = Interop.Nfc.NdefMessage.Create(out _messageHandle);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to create Ndef message, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 15
0
        private void Initialize()
        {
            int ret = Interop.Nfc.Initialize();

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to Initialize Nfc, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets the state, whether an application to call this API is currently the activated handler for the category.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <returns>'True' when application is currently the activated handler, otherwise 'False'.</returns>
        /// <param name="seType">The type of the secure element.</param>
        /// <param name="category">Enumeration value of the category.</param>
        /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public bool IsActivatedHandlerForCategory(NfcSecureElementType seType, NfcCardEmulationCategoryType category)
        {
            bool isActivatedHandle = false;
            int  ret = Interop.Nfc.CardEmulation.IsActivatedHandlerForCategory((int)seType, (int)category, out isActivatedHandle);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to check activated handle for category, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(isActivatedHandle);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets the current connected P2P target.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <returns>The NfcP2p object.</returns>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public NfcP2p GetConnectedTarget()
        {
            IntPtr targetHandle = IntPtr.Zero;
            int    ret          = Interop.Nfc.GetConnectedTarget(out targetHandle);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get connected p2p target, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
            _p2pTarget = new NfcP2p(targetHandle);

            return(_p2pTarget);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the current connected tag.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <returns>The NfcTag object.</returns>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public NfcTag GetConnectedTag()
        {
            IntPtr tagHandle = IntPtr.Zero;
            int    ret       = Interop.Nfc.GetConnectedTag(out tagHandle);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get connected tag, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
            _tag = new NfcTag(tagHandle);

            return(_tag);
        }
Ejemplo n.º 19
0
        private void RegisterHostCardEmulationEvent()
        {
            _hostCardEmulationEventCallback = (IntPtr handle, int eventType, IntPtr apdu, uint apduLen, IntPtr userData) =>
            {
                IntPtr      _seHandle        = handle;
                NfcHceEvent _hcdEventType    = (NfcHceEvent)eventType;
                byte[]      _apdu            = NfcConvertUtil.UintLengthIntPtrToByteArray(apdu, apduLen);
                HostCardEmulationEventArgs e = new HostCardEmulationEventArgs(_seHandle, _hcdEventType, _apdu);
                _hostCardEmulationEvent.SafeInvoke(null, e);
            };

            int ret = Interop.Nfc.SetHostCardEmulationEventCallback(_hostCardEmulationEventCallback, IntPtr.Zero);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to set host card emulation event callback, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Formats the detected tag that can store the NDEF message.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="keyValue">The key value that may need to format the tag.</param>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public Task <NfcError> FormatNdefMessageAsync(byte[] keyValue)
        {
            var task = new TaskCompletionSource <NfcError>();

            Interop.Nfc.VoidCallback callback = (int result, IntPtr userData) =>
            {
                task.SetResult((NfcError)result);
                return;
            };

            int ret = Interop.Nfc.Tag.FormatNdef(_tagHandle, keyValue, keyValue.Length, callback, IntPtr.Zero);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to format ndef message, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(task.Task);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Writes the NDEF formatted data.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="ndefMessage">The NfcNdefMessage object.</param>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public Task <NfcError> WriteNdefMessageAsync(NfcNdefMessage ndefMessage)
        {
            var task = new TaskCompletionSource <NfcError>();

            Interop.Nfc.VoidCallback callback = (int result, IntPtr userData) =>
            {
                task.SetResult((NfcError)result);
                return;
            };

            int ret = Interop.Nfc.Tag.WriteNdef(_tagHandle, ndefMessage.GetHandle(), callback, IntPtr.Zero);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to write ndef message, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(task.Task);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Reads the NDEF formatted data from the NFC tag.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public Task <NfcNdefMessage> ReadNdefMessageAsync()
        {
            int requestId = 0;
            var task      = new TaskCompletionSource <NfcNdefMessage>();

            lock (this)
            {
                requestId = _requestId++;
                _readNdefTaskSource[requestId] = task;
            }

            int ret = Interop.Nfc.Tag.ReadNdef(_tagHandle, _nativeTagReadCallback, (IntPtr)requestId);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to read ndef message, Error - " + (NfcError)ret);
                _readNdefTaskSource.Remove(requestId);
                NfcErrorFactory.ThrowNfcException(ret);
            }
            return(task.Task);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Transceives the data of the raw format card.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="buffer">The binary data for a parameter or additional commands.</param>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the the method fails due to an invalid operation.</exception>
        public Task <byte[]> TransceiveAsync(byte[] buffer)
        {
            int requestId = 0;
            var task      = new TaskCompletionSource <byte[]>();

            lock (this)
            {
                requestId = _requestId++;
                _transceiveTaskSource[requestId] = task;
            }

            int ret = Interop.Nfc.Tag.Transceive(_tagHandle, buffer, buffer.Length, _nativeTransceiveCallback, (IntPtr)requestId);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to transceive data, Error - " + (NfcError)ret);
                _transceiveTaskSource.Remove(requestId);
                NfcErrorFactory.ThrowNfcException(ret);
            }
            return(task.Task);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Formats the detected tag that can store the NDEF message.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="keyValue">The key value that may need to format the tag.</param>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public Task <NfcError> FormatNdefMessageAsync(byte[] keyValue)
        {
            int requestId = 0;
            var task      = new TaskCompletionSource <NfcError>();

            lock (this)
            {
                requestId = _requestId++;
                _voidTaskSource[requestId] = task;
            }

            int ret = Interop.Nfc.Tag.FormatNdef(_tagHandle, keyValue, keyValue.Length, _nativeVoidCallback, (IntPtr)requestId);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to format ndef message, Error - " + (NfcError)ret);
                _voidTaskSource.Remove(requestId);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(task.Task);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Retrieves all registered AIDs.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <returns>The list of NfcRegisteredAidInformation objects.</returns>
        /// <param name="seType">The type of the secure element.</param>
        /// <param name="category">Enumeration value of the category.</param>
        /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
        public IEnumerable <NfcRegisteredAidInformation> GetRegisteredAidInformation(NfcSecureElementType seType, NfcCardEmulationCategoryType category)
        {
            List <NfcRegisteredAidInformation> infoList = new List <NfcRegisteredAidInformation>();

            Interop.Nfc.SecureElementRegisteredAidCallback callback = (int type, IntPtr aid, bool readOnly, IntPtr userData) =>
            {
                if (aid != IntPtr.Zero)
                {
                    NfcRegisteredAidInformation aidInfo = new NfcRegisteredAidInformation((NfcSecureElementType)type, Marshal.PtrToStringAnsi(aid), readOnly);

                    infoList.Add(aidInfo);
                }
            };

            int ret = Interop.Nfc.CardEmulation.ForeachRegisterdAids((int)seType, (int)category, callback, IntPtr.Zero);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get all registerd aid informations, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(infoList);
        }