MESSAGE("build nfc-common-lib and nfc-manager")
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(LIBDIR "${PREFIX}/lib")
+SET(MODULEDIR "${LIBDIR}/nfc")
+
+ADD_DEFINITIONS("-D_GNU_SOURCE")
+#ADD_DEFINITIONS("-DSECURITY_SERVER")
+
ADD_SUBDIRECTORY(src/commonlib)
ADD_SUBDIRECTORY(src/clientlib)
ADD_SUBDIRECTORY(src/manager)
-ADD_SUBDIRECTORY(test_clinet_app/ndef-tool)
-
+#ADD_SUBDIRECTORY(test_clinet_app/ndef-tool)
+#ADD_SUBDIRECTORY(test_clinet_app/nfc_client)
+ADD_SUBDIRECTORY(tests)
#include <net_nfc_data.h>
#include <net_nfc_typedef.h>
-#include <net_nfc_typedef_private.h>
-#include <net_nfc_util_private.h>
+#include <net_nfc_typedef_internal.h>
+#include <net_nfc_util_internal.h>
enum {
#include <net_nfc_exchanger.h>
#include <net_nfc_typedef.h>
-#include <net_nfc_typedef_private.h>
-#include <net_nfc_util_private.h>
+#include <net_nfc_typedef_internal.h>
+#include <net_nfc_util_internal.h>
enum {
#include <tet_api.h>
#include "net_nfc_tag.h"
-#include "net_nfc_typedef_private.h"
+#include "net_nfc_typedef_internal.h"
#include "net_nfc_internal_se.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_data.h"
#include <stdint.h>
#include "net_nfc_ndef_message.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc.h" // to use net_nfc_data
char url[] = "samsung.com";
ndef_record_h record = NULL;
ndef_message_h msg = NULL;
- int length = 0;
+ uint32_t length = 0;
net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
net_nfc_append_record_to_ndef_message(msg, record);
- ret = net_nfc_get_ndef_message_byte_length( msg , &length);
+ ret = net_nfc_get_ndef_message_byte_length(msg , &length);
dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_byte_length is failed");
}
#include "net_nfc_ndef_record.h"
#include "net_nfc_ndef_message.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_data.h"
-//#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
+//#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
enum {
#include "net_nfc.h"
#include "net_nfc_typedef.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#ifdef SECURITY_SERVER
#include <security-server.h>
#include <tet_api.h>
#include <stdint.h>
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc.h"
#include "net_nfc_ndef_record.h"
#include "net_nfc_ndef_message.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_data.h"
#include "net_nfc.h"
#include "net_nfc_tag_felica.h"
#include <tet_api.h>
#include "net_nfc_tag.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_tag_jewel.h"
#include "net_nfc_target_info.h"
#include "net_nfc.h"
#include <tet_api.h>
#include "net_nfc_tag.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_tag_jewel.h"
#include "net_nfc_target_info.h"
#include "net_nfc.h"
#include <tet_api.h>
#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_private.h"
+#include "net_nfc_typedef_internal.h"
#include "net_nfc_target_info.h"
#include "net_nfc_data.h"
#include <stdbool.h>
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = SLP-Developer Library
-PROJECT_NUMBER =
+PROJECT_NUMBER =
OUTPUT_DIRECTORY = ./doxygen_output
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
ALWAYS_DETAILED_SEC = YES
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
-STRIP_FROM_PATH =
-STRIP_FROM_INC_PATH =
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
SHORT_NAMES = YES
JAVADOC_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = YES
TAB_SIZE = 8
-ALIASES =
+ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
BUILTIN_STL_SUPPORT = NO
GENERATE_TESTLIST = NO
GENERATE_BUGLIST = NO
GENERATE_DEPRECATEDLIST= NO
-ENABLED_SECTIONS =
+ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = NO
-FILE_VERSION_FILTER =
+FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
-# The QUIET tag can be used to turn on/off the messages that are generated
+# The QUIET tag can be used to turn on/off the messages that are generated
# by doxygen. Possible values are YES and NO. If left blank NO is used.
QUIET = NO
-# The WARNINGS tag can be used to turn on/off the warning messages that are
-# generated by doxygen. Possible values are YES and NO. If left blank
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
# NO is used.
WARNINGS = YES
-# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
-# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
# automatically be disabled.
WARN_IF_UNDOCUMENTED = YES
-# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
-# potential errors in the documentation, such as not documenting some
-# parameters in a documented function, or documenting parameters that
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
# don't exist or using markup commands wrongly.
WARN_IF_DOC_ERROR = YES
-# This WARN_NO_PARAMDOC option can be abled to get warnings for
-# functions that are documented, but have no documentation for their parameters
-# or return value. If set to NO (the default) doxygen will only warn about
-# wrong or incomplete parameter documentation, but not about the absence of
+# This WARN_NO_PARAMDOC option can be abled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
# documentation.
WARN_NO_PARAMDOC = NO
-# The WARN_FORMAT tag determines the format of the warning messages that
-# doxygen can produce. The string should contain the $file, $line, and $text
-# tags, which will be replaced by the file and line number from which the
-# warning originated and the warning text. Optionally the format may contain
-# $version, which will be replaced by the version of the file (if it could
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
# be obtained via FILE_VERSION_FILTER)
WARN_FORMAT = "$file:$line: $text"
-# The WARN_LOGFILE tag can be used to specify a file to which warning
-# and error messages should be written. If left blank the output is written
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
# to stderr.
-WARN_LOGFILE =
+WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
-# The INPUT tag can be used to specify the files and/or directories that contain
-# documented source files. You may enter file names like "myfile.cpp" or
-# directories like "/usr/src/myproject". Separate the files or directories
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
#INPUT = ..
INPUT = ../src/commonlib/include/net_nfc_typedef.h ../src/clientlib/include/net_nfc_target_info.h ../src/clientlib/include/net_nfc_llcp.h ../src/clientlib/include/net_nfc_exchanger.h ../src/clientlib/include/net_nfc_ndef_message.h ../src/clientlib/include/net_nfc_data.h ../src/clientlib/include/net_nfc_ndef_record.h ../src/clientlib/include/net_nfc_apdu.h ../src/clientlib/include/net_nfc_tag.h ../src/clientlib/include/net_nfc.h ../src/clientlib/include/net_nfc_ndef_message_handover.h ../src/clientlib/include/net_nfc_tag_felica.h ../src/clientlib/include/net_nfc_tag_jewel.h ../src/clientlib/include/net_nfc_tag_mifare.h
-# This tag can be used to specify the character encoding of the source files that
-# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default
-# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding.
+# This tag can be used to specify the character encoding of the source files that
+# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default
+# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding.
# See http://www.gnu.org/software/libiconv for the list of possible encodings.
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.h \
*.doxy
RECURSIVE = YES
-EXCLUDE =
+EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = */test/* \
*/debian/* \
*/arm/* \
*/simulator/* \
*test* \
- */voda3rd/*
-EXCLUDE_SYMBOLS =
-EXAMPLE_PATH =
-EXAMPLE_PATTERNS =
+ */voda3rd/*
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
-IMAGE_PATH = ../image
-INPUT_FILTER =
-FILTER_PATTERNS =
+IMAGE_PATH = ../image
+INPUT_FILTER =
+FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will
-# be generated. Documented entities will be cross-referenced with these sources.
-# Note: To get rid of all source code in the generated output, make sure also
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
# VERBATIM_HEADERS is set to NO.
SOURCE_BROWSER = NO
-# Setting the INLINE_SOURCES tag to YES will include the body
+# Setting the INLINE_SOURCES tag to YES will include the body
# of functions and classes directly in the documentation.
INLINE_SOURCES = NO
-# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
-# doxygen to hide any special comment blocks from generated source code
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
# fragments. Normal C and C++ comments will always remain visible.
STRIP_CODE_COMMENTS = YES
-# If the REFERENCED_BY_RELATION tag is set to YES (the default)
-# then for each documented function all documented
+# If the REFERENCED_BY_RELATION tag is set to YES (the default)
+# then for each documented function all documented
# functions referencing it will be listed.
REFERENCED_BY_RELATION = YES
-# If the REFERENCES_RELATION tag is set to YES (the default)
-# then for each documented function all documented entities
+# If the REFERENCES_RELATION tag is set to YES (the default)
+# then for each documented function all documented entities
# called/used by that function will be listed.
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
-# If the USE_HTAGS tag is set to YES then the references to source code
-# will point to the HTML generated by the htags(1) tool instead of doxygen
-# built-in source browser. The htags tool is part of GNU's global source
-# tagging system (see http://www.gnu.org/software/global/global.html). You
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
# will need version 4.8.6 or higher.
USE_HTAGS = NO
-# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
-# will generate a verbatim copy of the header file for each class for
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
# which an include is specified. Set to NO to disable this.
VERBATIM_HEADERS = YES
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
-# of all compounds will be generated. Enable this if the project
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
# contains a lot of classes, structs, unions or interfaces.
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 10
-IGNORE_PREFIX =
+IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
-# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
# generate HTML output.
GENERATE_HTML = YES
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `html' will be used as the default path.
HTML_OUTPUT = html
-# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
-# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
# doxygen will generate files with .html extension.
HTML_FILE_EXTENSION = .html
-# The HTML_HEADER tag can be used to specify a personal HTML header for
-# each generated HTML page. If it is left blank doxygen will generate a
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
# standard header.
-HTML_HEADER =
+HTML_HEADER =
-# The HTML_FOOTER tag can be used to specify a personal HTML footer for
-# each generated HTML page. If it is left blank doxygen will generate a
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
# standard footer.
HTML_FOOTER =
-# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
-# style sheet that is used by each HTML page. It can be used to
-# fine-tune the look of the HTML output. If the tag is left blank doxygen
-# will generate a default style sheet. Note that doxygen will try to copy
-# the style sheet file to the HTML output directory, so don't put your own
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
# stylesheet in the HTML output directory as well, or it will be erased!
HTML_STYLESHEET =./slp_doxy.css
-# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
-# files or namespaces will be aligned in HTML using tables. If set to
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
# NO a bullet list will be used.
HTML_ALIGN_MEMBERS = YES
-# If the GENERATE_HTMLHELP tag is set to YES, additional index files
-# will be generated that can be used as input for tools like the
-# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
# of the generated HTML documentation.
GENERATE_HTMLHELP = YES
-# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
-# be used to specify the file name of the resulting .chm file. You
-# can add a path in front of the file if the result should not be
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
# written to the html output directory.
-CHM_FILE =
+CHM_FILE =
-# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
-# be used to specify the location (absolute path including file name) of
-# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
# the HTML help compiler on the generated index.hhp.
-HHC_LOCATION =
+HHC_LOCATION =
-# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
-# controls if a separate .chi index file is generated (YES) or that
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
# it should be included in the master .chm file (NO).
GENERATE_CHI = NO
-# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
-# controls whether a binary table of contents is generated (YES) or a
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
# normal table of contents (NO) in the .chm file.
BINARY_TOC = NO
-# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
# to the contents of the HTML help documentation and to the tree view.
TOC_EXPAND = NO
-# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
-# top of each HTML page. The value NO (the default) enables the index and
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
# the value YES disables it.
DISABLE_INDEX = NO
-# This tag can be used to set the number of enum values (range [1..20])
+# This tag can be used to set the number of enum values (range [1..20])
# that doxygen will group on one line in the generated HTML documentation.
ENUM_VALUES_PER_LINE = 4
# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
-# generated containing a tree-like index structure (just like the one that
-# is generated for HTML Help). For this to work a browser that supports
-# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+,
-# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are
+# generated containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+,
+# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are
# probably better off using the HTML help feature.
GENERATE_TREEVIEW = YES
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
-# used to set the initial width (in pixels) of the frame in which the tree
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
# is shown.
TREEVIEW_WIDTH = 190
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
-# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
# generate Latex output.
GENERATE_LATEX = NO
-# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `latex' will be used as the default path.
LATEX_OUTPUT = latex
-# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
# invoked. If left blank `latex' will be used as the default command name.
LATEX_CMD_NAME = latex
-# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
-# generate index for LaTeX. If left blank `makeindex' will be used as the
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
# default command name.
MAKEINDEX_CMD_NAME = makeindex
-# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
-# LaTeX documents. This may be useful for small projects and may help to
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
# save some trees in general.
COMPACT_LATEX = NO
-# The PAPER_TYPE tag can be used to set the paper type that is used
-# by the printer. Possible values are: a4, a4wide, letter, legal and
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
# executive. If left blank a4wide will be used.
PAPER_TYPE = a4wide
-# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
# packages that should be included in the LaTeX output.
-EXTRA_PACKAGES =
+EXTRA_PACKAGES =
-# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
-# the generated latex document. The header should contain everything until
-# the first chapter. If it is left blank doxygen will generate a
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
# standard header. Notice: only use this tag if you know what you are doing!
-LATEX_HEADER =
+LATEX_HEADER =
-# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
-# is prepared for conversion to pdf (using ps2pdf). The pdf file will
-# contain links (just like the HTML output) instead of page references
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
# This makes the output suitable for online browsing using a pdf viewer.
PDF_HYPERLINKS = NO
-# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
-# plain latex in the generated Makefile. Set this option to YES to get a
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
# higher quality PDF documentation.
USE_PDFLATEX = NO
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
-# command to the generated LaTeX files. This will instruct LaTeX to keep
-# running if errors occur, instead of asking the user for help.
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
# This option is also used when generating formulas in HTML.
LATEX_BATCHMODE = NO
-# If LATEX_HIDE_INDICES is set to YES then doxygen will not
-# include the index chapters (such as File Index, Compound Index, etc.)
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
# in the output.
LATEX_HIDE_INDICES = NO
# configuration options related to the RTF output
#---------------------------------------------------------------------------
-# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
-# The RTF output is optimized for Word 97 and may not look very pretty with
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
# other RTF readers or editors.
GENERATE_RTF = NO
-# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `rtf' will be used as the default path.
RTF_OUTPUT = rtf
-# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
-# RTF documents. This may be useful for small projects and may help to
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
# save some trees in general.
COMPACT_RTF = NO
-# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
-# will contain hyperlink fields. The RTF file will
-# contain links (just like the HTML output) instead of page references.
-# This makes the output suitable for online browsing using WORD or other
-# programs which support those fields.
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
# Note: wordpad (write) and others do not support links.
RTF_HYPERLINKS = NO
-# Load stylesheet definitions from file. Syntax is similar to doxygen's
-# config file, i.e. a series of assignments. You only have to provide
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
# replacements, missing definitions are set to their default value.
-RTF_STYLESHEET_FILE =
+RTF_STYLESHEET_FILE =
-# Set optional variables used in the generation of an rtf document.
+# Set optional variables used in the generation of an rtf document.
# Syntax is similar to doxygen's config file.
-RTF_EXTENSIONS_FILE =
+RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
-# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
# generate man pages
GENERATE_MAN = NO
-# The MAN_OUTPUT tag is used to specify where the man pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `man' will be used as the default path.
MAN_OUTPUT = man
-# The MAN_EXTENSION tag determines the extension that is added to
+# The MAN_EXTENSION tag determines the extension that is added to
# the generated man pages (default is the subroutine's section .3)
MAN_EXTENSION = .3
-# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
-# then it will generate one additional man file for each entity
-# documented in the real man page(s). These additional files
-# only source the real man page, but without them the man command
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
# would be unable to find the correct page. The default is NO.
MAN_LINKS = NO
# configuration options related to the XML output
#---------------------------------------------------------------------------
-# If the GENERATE_XML tag is set to YES Doxygen will
-# generate an XML file that captures the structure of
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
# the code including all documentation.
GENERATE_XML = NO
-# The XML_OUTPUT tag is used to specify where the XML pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `xml' will be used as the default path.
XML_OUTPUT = xml
-# The XML_SCHEMA tag can be used to specify an XML schema,
-# which can be used by a validating XML parser to check the
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
# syntax of the XML files.
-XML_SCHEMA =
+XML_SCHEMA =
-# The XML_DTD tag can be used to specify an XML DTD,
-# which can be used by a validating XML parser to check the
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
# syntax of the XML files.
-XML_DTD =
+XML_DTD =
-# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
-# dump the program listings (including syntax highlighting
-# and cross-referencing information) to the XML output. Note that
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
# enabling this will significantly increase the size of the XML output.
XML_PROGRAMLISTING = YES
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
-# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
-# generate an AutoGen Definitions (see autogen.sf.net) file
-# that captures the structure of the code including all
-# documentation. Note that this feature is still experimental
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
# and incomplete at the moment.
GENERATE_AUTOGEN_DEF = NO
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
-# If the GENERATE_PERLMOD tag is set to YES Doxygen will
-# generate a Perl module file that captures the structure of
-# the code including all documentation. Note that this
-# feature is still experimental and incomplete at the
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
# moment.
GENERATE_PERLMOD = NO
-# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
-# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
# to generate PDF and DVI output from the Perl module output.
PERLMOD_LATEX = YES
-# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
-# nicely formatted so it can be parsed by a human reader. This is useful
-# if you want to understand what is going on. On the other hand, if this
-# tag is set to NO the size of the Perl module output will be much smaller
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader. This is useful
+# if you want to understand what is going on. On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
# and Perl will parse it just the same.
PERLMOD_PRETTY = YES
-# The names of the make variables in the generated doxyrules.make file
-# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
-# This is useful so different doxyrules.make files included by the same
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
# Makefile don't overwrite each other's variables.
-PERLMOD_MAKEVAR_PREFIX =
+PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
+# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
-# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
-# evaluate all C-preprocessor directives found in the sources and include
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
# files.
ENABLE_PREPROCESSING = YES
-# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
-# names in the source code. If set to NO (the default) only conditional
-# compilation will be performed. Macro expansion can be done in a controlled
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
# way by setting EXPAND_ONLY_PREDEF to YES.
MACRO_EXPANSION = NO
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
-# then the macro expansion is limited to the macros specified with the
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
# PREDEFINED and EXPAND_AS_DEFINED tags.
EXPAND_ONLY_PREDEF = NO
-# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
# in the INCLUDE_PATH (see below) will be search if a #include is found.
SEARCH_INCLUDES = YES
-# The INCLUDE_PATH tag can be used to specify one or more directories that
-# contain include files that are not input files but should be processed by
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
# the preprocessor.
-INCLUDE_PATH =
+INCLUDE_PATH =
-# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
-# patterns (like *.h and *.hpp) to filter out the header-files in the
-# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
# be used.
-INCLUDE_FILE_PATTERNS =
+INCLUDE_FILE_PATTERNS =
-# The PREDEFINED tag can be used to specify one or more macro names that
-# are defined before the preprocessor is started (similar to the -D option of
-# gcc). The argument of the tag is a list of macros of the form: name
-# or name=definition (no spaces). If the definition and the = are
-# omitted =1 is assumed. To prevent a macro definition from being
-# undefined via #undef or recursively expanded use the := operator
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
-PREDEFINED =
+PREDEFINED =
-# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
-# this tag can be used to specify a list of macro names that should be expanded.
-# The macro definition that is found in the sources will be used.
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
# Use the PREDEFINED tag if you want to use a different macro definition.
-EXPAND_AS_DEFINED =
+EXPAND_AS_DEFINED =
-# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
-# doxygen's preprocessor will remove all function-like macros that are alone
-# on a line, have an all uppercase name, and do not end with a semicolon. Such
-# function macros are typically used for boiler-plate code, and will confuse
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse
# the parser if not removed.
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
-# Configuration::additions related to external references
+# Configuration::additions related to external references
#---------------------------------------------------------------------------
-# The TAGFILES option can be used to specify one or more tagfiles.
-# Optionally an initial location of the external documentation
-# can be added for each tagfile. The format of a tag file without
-# this location is as follows:
-# TAGFILES = file1 file2 ...
-# Adding location for the tag files is done as follows:
-# TAGFILES = file1=loc1 "file2 = loc2" ...
-# where "loc1" and "loc2" can be relative or absolute paths or
-# URLs. If a location is present for each tag, the installdox tool
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
# does not have to be run to correct the links.
# Note that each tag file must have a unique name
# (where the name does NOT include the path)
-# If a tag file is not located in the directory in which doxygen
+# If a tag file is not located in the directory in which doxygen
# is run, you must also specify the path to the tagfile here.
-TAGFILES =
+TAGFILES =
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
# a tag file that is based on the input files it reads.
-GENERATE_TAGFILE =
+GENERATE_TAGFILE =
-# If the ALLEXTERNALS tag is set to YES all external classes will be listed
-# in the class index. If set to NO only the inherited external classes
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
# will be listed.
ALLEXTERNALS = NO
-# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
-# in the modules index. If set to NO, only the current project's groups will
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
# be listed.
EXTERNAL_GROUPS = YES
-# The PERL_PATH should be the absolute path and name of the perl script
+# The PERL_PATH should be the absolute path and name of the perl script
# interpreter (i.e. the result of `which perl').
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
+# Configuration options related to the dot tool
#---------------------------------------------------------------------------
-# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
-# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
-# or super classes. Setting the tag to NO turns the diagrams off. Note that
-# this option is superseded by the HAVE_DOT option below. This is only a
-# fallback. It is recommended to install and use dot, since it yields more
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option is superseded by the HAVE_DOT option below. This is only a
+# fallback. It is recommended to install and use dot, since it yields more
# powerful graphs.
CLASS_DIAGRAMS = NO
-# You can define message sequence charts within doxygen comments using the \msc
-# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to
-# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to
-# specify the directory where the mscgen tool resides. If left empty the tool is assumed to
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to
+# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to
+# specify the directory where the mscgen tool resides. If left empty the tool is assumed to
# be found in the default search path.
-MSCGEN_PATH =
+MSCGEN_PATH =
-# If set to YES, the inheritance and collaboration graphs will hide
-# inheritance and usage relations if the target is undocumented
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
# or is not a class.
HIDE_UNDOC_RELATIONS = YES
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
-# available from the path. This tool is part of Graphviz, a graph visualization
-# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
# have no effect if this option is set to NO (the default)
HAVE_DOT = NO
-# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for each documented class showing the direct and
-# indirect inheritance relations. Setting this tag to YES will force the
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
# the CLASS_DIAGRAMS tag to NO.
CLASS_GRAPH = NO
-# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for each documented class showing the direct and
-# indirect implementation dependencies (inheritance, containment, and
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
# class references variables) of the class with other documented classes.
COLLABORATION_GRAPH = NO
-# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
# will generate a graph for groups, showing the direct groups dependencies
GROUP_GRAPHS = NO
-# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
-# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
# Language.
UML_LOOK = NO
-# If set to YES, the inheritance and collaboration graphs will show the
+# If set to YES, the inheritance and collaboration graphs will show the
# relations between templates and their instances.
TEMPLATE_RELATIONS = NO
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
-# tags are set to YES then doxygen will generate a graph for each documented
-# file showing the direct and indirect include dependencies of the file with
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
# other documented files.
INCLUDE_GRAPH = NO
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
-# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
-# documented header file showing the documented files that directly or
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
# indirectly include this file.
INCLUDED_BY_GRAPH = NO
-# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will
-# generate a call dependency graph for every global function or class method.
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable call graphs for selected
+# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will
+# generate a call dependency graph for every global function or class method.
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable call graphs for selected
# functions only using the \callgraph command.
CALL_GRAPH = NO
-# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will
-# generate a caller dependency graph for every global function or class method.
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable caller graphs for selected
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will
+# generate a caller dependency graph for every global function or class method.
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable caller graphs for selected
# functions only using the \callergraph command.
CALLER_GRAPH = NO
-# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
# will graphical hierarchy of all classes instead of a textual one.
GRAPHICAL_HIERARCHY = NO
-# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
-# then doxygen will show the dependencies a directory has on other directories
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
# in a graphical way. The dependency relations are determined by the #include
# relations between the files in the directories.
DIRECTORY_GRAPH = NO
-# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
# generated by dot. Possible values are png, jpg, or gif
# If left blank png will be used.
DOT_IMAGE_FORMAT = jpg
-# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found in the path.
-DOT_PATH =
+DOT_PATH =
-# The DOTFILE_DIRS tag can be used to specify one or more directories that
-# contain dot files that are included in the documentation (see the
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
# \dotfile command).
-DOTFILE_DIRS =
+DOTFILE_DIRS =
-# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
-# nodes that will be shown in the graph. If the number of nodes in a graph
-# becomes larger than this value, doxygen will truncate the graph, which is
-# visualized by representing a node as a red box. Note that doxygen will always
+# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen will always
# show the root nodes and its direct children regardless of this setting.
DOT_GRAPH_MAX_NODES = 50
-# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
-# background. This is disabled by default, which results in a white background.
-# Warning: Depending on the platform used, enabling this option may lead to
-# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, which results in a white background.
+# Warning: Depending on the platform used, enabling this option may lead to
+# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
# read).
DOT_TRANSPARENT = NO
-# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
-# files in one run (i.e. multiple -o and -T options on the command line). This
-# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
# support this, this feature is disabled by default.
DOT_MULTI_TARGETS = NO
-# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
-# generate a legend page explaining the meaning of the various boxes and
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
# arrows in the dot generated graphs.
GENERATE_LEGEND = NO
-# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
-# remove the intermediate dot files that are used to generate
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
# the various graphs.
DOT_CLEANUP = NO
#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine
+# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
-# The SEARCHENGINE tag specifies whether or not a search engine should be
+# The SEARCHENGINE tag specifies whether or not a search engine should be
# used. If set to NO the values of all tags below this one will be ignored.
SEARCHENGINE = YES
+++ /dev/null
-<manifest>
- <request>
- <domain name="_" />
- </request>
-</manifest>
-
+++ /dev/null
-<manifest>
- <request>
- <domain name="_" />
- </request>
-</manifest>
-
+++ /dev/null
-<manifest>
- <request>
- <domain name="_" />
- </request>
-</manifest>
-
# PATH should only include /usr/* if it runs after the mountnfs.sh script
DAEMON=/usr/bin/nfc-manager-daemon
-DAEMON_ARGS="script" # Arguments to run the daemon with
+DAEMON_ARGS="--daemon" # Arguments to run the daemon with
VCONFTOOL=/usr/bin/vconftool
-
+
# Exit if the package is not installed
-[ -x $DAEMON ] || exit 0
-[ -x $VCONFTOOL ] || exit 0
-
+[ -x $DAEMON ] || exit 0
+[ -x $VCONFTOOL ] || exit 0
+
#if vconftool get db/nfc/enable | grep -q "db/nfc/enable, value = 1 (bool)"
#then
if ! ps -f --ppid 1 | grep -q nfc-manager-daemon
[Unit]
Description=NFC manager
+After=tizen-boot.target telephony.service
[Service]
Type=simple
-ExecStart=/usr/bin/nfc-manager-daemon
+ExecStart=/usr/bin/nfc-manager-daemon --dbus
KillSignal=SIGKILL
[Install]
Name: nfc-manager
Summary: NFC framework manager
-Version: 0.0.45
+Version: 0.1.0
Release: 0
Group: libs
License: Flora Software License
Source0: %{name}-%{version}.tar.gz
Source1: libnfc-manager-0.init.in
Source2: nfc-manager.service
-Source1001: nfc-manager.manifest
+Source1001: %{name}.manifest
+BuildRequires: cmake
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(gobject-2.0)
BuildRequires: pkgconfig(security-server)
-BuildRequires: pkgconfig(dbus-glib-1)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(tapi)
-BuildRequires: pkgconfig(ecore)
BuildRequires: pkgconfig(bluetooth-api)
BuildRequires: pkgconfig(mm-sound)
BuildRequires: pkgconfig(appsvc)
-BuildRequires: pkgconfig(heynoti)
BuildRequires: pkgconfig(svi)
BuildRequires: pkgconfig(capi-media-wav-player)
-BuildRequires: pkgconfig(smartcard-service)
-BuildRequires: pkgconfig(smartcard-service-common)
BuildRequires: pkgconfig(libssl)
-BuildRequires: pkgconfig(pmapi)
BuildRequires: pkgconfig(pkgmgr)
BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(ecore-x)
-BuildRequires: pkgconfig(capi-appfw-app-manager)
-BuildRequires: cmake
+BuildRequires: pkgconfig(pmapi)
+BuildRequires: python
+BuildRequires: python-xml
BuildRequires: gettext-tools
Requires(post): /sbin/ldconfig
Requires(post): /usr/bin/vconftool
-requires(postun): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+Requires: nfc-common-lib = %{version}
+Requires: nfc-client-lib = %{version}
%description
%setup -q
cp %{SOURCE1001} .
-
-%package devel
-Summary: Download agent
-Group: Development/Libraries
-Requires: %{name} = %{version}-%{release}
-
-
-%description devel
-NFC library Manager (devel)
-
-
%package -n nfc-common-lib
Summary: NFC common library
Group: Development/Libraries
-Requires: %{name} = %{version}-%{release}
%description -n nfc-common-lib
%package -n nfc-common-lib-devel
Summary: NFC common library (devel)
Group: libs
-Requires: %{name} = %{version}-%{release}
+Requires: nfc-common-lib = %{version}
%description -n nfc-common-lib-devel
NFC common library (devel)
-%build
-export LDFLAGS+="-Wl,--rpath=%{_libdir} -Wl,--as-needed"
-mkdir cmake_tmp
-cd cmake_tmp
-LDFLAGS="$LDFLAGS" %cmake ..
+%package -n nfc-client-lib
+Summary: NFC client library
+Group: Development/Libraries
+Requires: nfc-common-lib = %{version}
+
+
+%description -n nfc-client-lib
+NFC Client library.
+
+
+%package -n nfc-client-lib-devel
+Summary: NFC client library (devel)
+Group: libs
+Requires: nfc-client-lib = %{version}
+
+
+%description -n nfc-client-lib-devel
+NFC client library (devel)
+
+
+#%package -n nfc-client-test
+#Summary: NFC client test
+#Group: Development/Libraries
+#Requires: %{name} = %{version}-%{release}
+
-make
+#%description -n nfc-client-test
+#NFC client test (devel)
+
+
+%build
+export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"
+LDFLAGS="$LDFLAGS" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
%install
-cd cmake_tmp
%make_install
-cd ..
-%__mkdir -p %{buildroot}/etc/init.d/
-%__cp -af %SOURCE1 %{buildroot}/etc/init.d/libnfc-manager-0
-chmod 755 %{buildroot}/etc/init.d/libnfc-manager-0
-mkdir -p %{buildroot}/usr/share/license
-cp -af LICENSE.Flora %{buildroot}/usr/share/license/nfc-common-lib
-cp -af LICENSE.Flora %{buildroot}/usr/share/license/nfc-manager
-mkdir -p %{buildroot}/usr/lib/systemd/system/multi-user.target.wants
-cp -af %{SOURCE2} %{buildroot}/usr/lib/systemd/system/
-ln -s ../nfc-manager.service %{buildroot}/usr/lib/systemd/system/multi-user.target.wants/nfc-manager.service
+install -D -m 0755 %SOURCE1 %{buildroot}%{_sysconfdir}/init.d/libnfc-manager-0
+mkdir -p %{buildroot}/opt/usr/share/nfc_debug
+mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
+cp -af %{SOURCE2} %{buildroot}%{_libdir}/systemd/system/
+ln -s ../%{name}.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/%{name}.service
%post
/sbin/ldconfig
-vconftool set -t bool db/nfc/feature 1 -u 5000 -f
-vconftool set -t bool db/nfc/enable 0 -u 5000 -f
-vconftool set -t bool db/nfc/sbeam 0 -u 5000 -f
-vconftool set -t int db/nfc/se_type 0 -u 5000 -f
-vconftool set -t bool db/nfc/predefined_item_state 0 -u 5000 -f
-vconftool set -t string db/nfc/predefined_item "None" -u 5000 -f
-
-ln -s /etc/init.d/libnfc-manager-0 /etc/rc.d/rc3.d/S81libnfc-manager-0 -f
-ln -s /etc/init.d/libnfc-manager-0 /etc/rc.d/rc5.d/S81libnfc-manager-0 -f
+#ln -s /etc/init.d/libnfc-manager-0 /etc/rc.d/rc3.d/S81libnfc-manager-0 -f
+#ln -s /etc/init.d/libnfc-manager-0 /etc/rc.d/rc5.d/S81libnfc-manager-0 -f
-mkdir -p /opt/etc/nfc_debug
-chown :5000 /opt/etc/nfc_debug
-chmod 775 /opt/etc/nfc_debug
systemctl daemon-reload
if [ $1 == 1 ]; then
- systemctl restart nfc-manager.service
+ systemctl restart %{name}.service
fi
+%post -n nfc-client-lib
+/sbin/ldconfig
+vconftool set -t bool db/nfc/feature 0 -u 5000 -f
+vconftool set -t int db/nfc/se_type 0 -u 5000 -f
+vconftool set -t bool db/nfc/predefined_item_state 0 -u 5000 -f
+vconftool set -t string db/nfc/predefined_item "None" -u 5000 -f
+vconftool set -t bool db/nfc/enable 0 -u 5000 -f
+
%postun
/sbin/ldconfig
-mkdir -p /etc/rc.d/rc3.d
-mkdir -p /etc/rc.d/rc5.d
-rm -f /etc/rc.d/rc3.d/S81libnfc-manager-0
-rm -f /etc/rc.d/rc5.d/S81libnfc-manager-0
+#mkdir -p /etc/rc.d/rc3.d
+#mkdir -p /etc/rc.d/rc5.d
+#rm -f /etc/rc.d/rc3.d/S81libnfc-manager-0
+#rm -f /etc/rc.d/rc5.d/S81libnfc-manager-0
if [ $1 == 0 ]; then
- systemctl stop nfc-manager.service
+ systemctl stop %{name}.service
fi
systemctl daemon-reload
%files
%manifest %{name}.manifest
%defattr(-,root,root,-)
-%{_libdir}/libnfc.so.1
-%{_libdir}/libnfc.so.1.0.0
-%{_prefix}/bin/nfc-manager-daemon
-%{_prefix}/bin/ndef-tool
-/etc/init.d/libnfc-manager-0
-%{_datadir}/dbus-1/services/org.tizen.nfc_service.service
-/usr/share/license/nfc-manager
-/usr/lib/systemd/system/nfc-manager.service
-/usr/lib/systemd/system/multi-user.target.wants/nfc-manager.service
-
-
-%files devel
+%{_bindir}/nfc-manager-daemon
+#%{_bindir}/ndef-tool
+%{_libdir}/systemd/system/%{name}.service
+%{_libdir}/systemd/system/multi-user.target.wants/%{name}.service
+%{_sysconfdir}/init.d/libnfc-manager-0
+%{_datadir}/dbus-1/services/org.tizen.NetNfcService.service
+%{_datadir}/packages/%{name}.xml
+%{_datadir}/nfc-manager-daemon/sounds/*
+%attr(0775,-,5000) %dir /opt/usr/share/nfc_debug
+%license LICENSE.Flora
+
+
+%files -n nfc-client-lib
%manifest %{name}.manifest
%defattr(-,root,root,-)
+%{_libdir}/libnfc.so.*
+%license LICENSE.Flora
+
+
+%files -n nfc-client-lib-devel
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
+%{_libdir}/libnfc.so
%{_libdir}/pkgconfig/nfc.pc
%{_includedir}/nfc/*.h
-%{_libdir}/libnfc.so
%files -n nfc-common-lib
%manifest %{name}.manifest
%defattr(-,root,root,-)
-%{_libdir}/libnfc-common-lib.so.1
-%{_libdir}/libnfc-common-lib.so.1.0.0
-/usr/share/license/nfc-common-lib
-/usr/share/nfc-manager-daemon/sounds/*
+%{_libdir}/libnfc-common-lib.so.*
+%{_datadir}/nfc-manager-daemon/sounds/*
+%license LICENSE.Flora
%files -n nfc-common-lib-devel
%{_libdir}/libnfc-common-lib.so
%{_libdir}/pkgconfig/nfc-common-lib.pc
%{_includedir}/nfc-common-lib/*.h
+
+
+#%files -n nfc-client-test
+#%manifest nfc-client-test.manifest
+#%defattr(-,root,root,-)
+#%{_bindir}/nfc_client
+#%license LICENSE.Flora
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-#PROJECT(nfc C)
PROJECT(nfc-client-lib C)
#SET(NFC_CLIENT_LIB "nfc-client-lib")
SET(VERSION_MAJOR 1)
SET(VERSION ${VERSION_MAJOR}.0.0)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../commonlib/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../manager/include)
+include_directories(${CMAKE_SOURCE_DIR}/src/commonlib)
+include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
+include_directories(${CMAKE_SOURCE_DIR}/src/manager/include)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} CLIENT_SRCS)
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
INCLUDE(FindPkgConfig)
-pkg_check_modules(clientlib_pkges REQUIRED security-server dbus-glib-1 dlog ecore vconf)
+pkg_check_modules(clientlib_pkges REQUIRED security-server dlog ecore-x vconf)
FOREACH(flag ${clientlib_pkges_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDIF()
ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-#ADD_DEFINITIONS("-DSLP_DEBUG")
-
-ADD_DEFINITIONS("-DNFC_FIRMWARE_UPDATE")
-ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE")
-ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN")
-ADD_DEFINITIONS("-DUSE_IPC_EPOLL -DUSE_EPOLL_TIMEOUT")
-ADD_DEFINITIONS("-DLLCP_MODE")
-ADD_DEFINITIONS("-DNFC_APP_SUPPORTED")
-ADD_DEFINITIONS("-DSAVE_TARGET_INFO_IN_CC")
-ADD_DEFINITIONS("-DSECURITY_SERVER")
-#ADD_DEFINITIONS("-DG_MAIN_LOOP")
-#ADD_DEFINITIONS("-DUSE_ECORE_MAIN_LOOP")
-ADD_DEFINITIONS("-DUSE_GLIB_MAIN_LOOP")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
ADD_LIBRARY(${NFC_CLIENT_LIB} SHARED ${CLIENT_SRCS})
SET_TARGET_PROPERTIES(${NFC_CLIENT_LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(${NFC_CLIENT_LIB} PROPERTIES VERSION ${VERSION})
-TARGET_LINK_LIBRARIES(${NFC_CLIENT_LIB} ${clientlib_pkges_LDFLAGS} "-L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/commonlib/" "-lnfc-common-lib")
+TARGET_LINK_LIBRARIES(${NFC_CLIENT_LIB} ${clientlib_pkges_LDFLAGS} nfc-common-lib)
+
+LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib)
+
SET(CLIENT_HEADER
- ../commonlib/include/net_nfc_typedef.h
+ ${CMAKE_SOURCE_DIR}/src/commonlib/include/net_nfc_typedef.h
include/net_nfc.h
+ include/net_nfc_data.h
include/net_nfc_target_info.h
- include/net_nfc_tag.h
- include/net_nfc_tag_jewel.h
- include/net_nfc_tag_mifare.h
- include/net_nfc_tag_felica.h
- include/net_nfc_llcp.h
- include/net_nfc_ndef_record.h
include/net_nfc_ndef_message.h
- include/net_nfc_ndef_message_handover.h
+ include/net_nfc_ndef_record.h
include/net_nfc_sign_record.h
- include/net_nfc_data.h
- include/net_nfc_exchanger.h
- include/net_nfc_internal_se.h
- include/net_nfc_test.h
- ../manager/include/nfc-service-glue.h
- ../manager/include/net_nfc_manager_dbus.h
+ include/net_nfc_ndef_message_handover.h
+ include/net_nfc_client_context.h
+ include/net_nfc_client_manager.h
+ include/net_nfc_client_system_handler.h
+ include/net_nfc_client_transceive.h
+ include/net_nfc_client_tag.h
+ include/net_nfc_client_ndef.h
+ include/net_nfc_client_llcp.h
+ include/net_nfc_client_p2p.h
+ include/net_nfc_client_snep.h
+ include/net_nfc_client_exchanger.h
+ include/net_nfc_client_handover.h
+ include/net_nfc_client_se.h
+ include/net_nfc_client_tag_felica.h
+ include/net_nfc_client_tag_jewel.h
+ include/net_nfc_tag_mifare.h
+ include/net_nfc_client_test.h
)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nfc.pc DESTINATION lib/pkgconfig)
-INSTALL(TARGETS ${NFC_CLIENT_LIB} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${NFC_CLIENT_LIB} DESTINATION lib)
FOREACH(hfile ${CLIENT_HEADER})
- INSTALL(FILES ${hfile} DESTINATION include/nfc)
+ INSTALL(FILES ${hfile} DESTINATION include/nfc)
ENDFOREACH(hfile)
-
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/**
- NFC Manager
- NFC Manager controls the nfc device with high level APIs such as SmartPoster and Connection handover.
- It also support the JSR257 push handling.
- this file is provide the APIs of NFC Manager
-
- @file net_nfc.h
- modified by:
- Sechang Sohn (sc.sohn@samsung.com)
- Sangsoo Lee (constant.lee@samsung.com)
- Sungjae Lim (neueziel.lim@samsung.com)
- Junyong Sim (junyong.sim@samsung.com)
- Wonkyu Kwon (wonkyu.kwon@samsung.com)
- @version 0.1
- @brief This file provide the APIs of the NFC Manager
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
-#ifndef __NET_NFC_INTERFACE_H__
-#define __NET_NFC_INTERFACE_H__
-
-#include <net_nfc_typedef.h>
-#include <net_nfc_tag.h>
-#include <net_nfc_tag_jewel.h>
-#include <net_nfc_tag_mifare.h>
-#include <net_nfc_tag_felica.h>
-#include <net_nfc_llcp.h>
-#include <net_nfc_target_info.h>
-#include <net_nfc_ndef_message.h>
-#include <net_nfc_ndef_record.h>
-#include <net_nfc_data.h>
-#include <net_nfc_ndef_message_handover.h>
-#include <net_nfc_internal_se.h>
-#include <net_nfc_test.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define NET_NFC_SERVICE_EMPTY_TYPE "http://tizen.org/appcontrol/operation/nfc/empty"
-#define NET_NFC_SERVICE_WELL_KNOWN_TYPE "http://tizen.org/appcontrol/operation/nfc/wellknown"
-#define NET_NFC_SERVICE_EXTERNAL_TYPE "http://tizen.org/appcontrol/operation/nfc/external"
-#define NET_NFC_SERVICE_MIME_TYPE "http://tizen.org/appcontrol/operation/nfc/mime"
-#define NET_NFC_SERVICE_URI_TYPE "http://tizen.org/appcontrol/operation/nfc/uri"
-
-/**
-
-@addtogroup NET_NFC_MANAGER_API
-@{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <net_nfc_typedef.h>
-
- @li @c #net_nfc_initialize Initialize the nfc-manager
- @li @c #net_nfc_deinitialize deinitialize the nfc-manager
- @li @c #net_nfc_set_response_callback register callback function for async response and detection events
- @li @c #net_nfc_unset_response_callback unregister callback
-
-*/
-
-/**
- "net_nfc_intialize" initializes NFC Manager.
- This function must be called before proceed any function of NFC Manager excepting net_nfc_set_exchanger_cb.
- Internally it make socket connection to NFC-Manager.
- When the client process crashed or exit without the deinit. nfc-manager
- auto matically process deinit itself.
-
- In running time, application can have a only one functionality of nfc client and nfc exchanger listener
- Both can not be co-existed. So, If application want to be a exchanger listener, then do not call net_nfc_initialize. if net_nfc_initialize is called before,
- net_nfc_deintialize SHOULD be called first, and then net_nfc_set_exchange_cb will be available.
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @return return the result of calling this functions
-
- @exception NET_NFC_ALREADY_INITIALIZED already initialized
- @exception NET_NFC_IPC_FAIL communication to server is failed
- @exception NET_NFC_ALLOC_FAIL memory allocation failed
- @exception NET_NFC_THREAD_CREATE_FAIL failed to create thread for main event delivery
- @exception NET_NFC_NOT_ALLOWED_OPERATION exchanger_cb is already register.
-
- <br>
-
- example codes
- @code
- int main ()
- {
- net_nfc_error_e result;
- result = net_nfc_initialize();
- if (result != NET_NFC_OK) {
- printf ("initialize error: %d\n", result);
- }
-
- return 0;
- }
- @endcode
-
-*/
-net_nfc_error_e net_nfc_initialize(void);
-
-/**
- the net_nfc_deinitialize function free the all the resource of the NFC Manager and
- disconnect session of connection from application to the Manager.
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @return return the result of the calling this function
-
- sample codes
- @code
-
- @exception NONE
-
- int main (void)
- {
- if(NET_NFC_OK != net_nfc_initialize()){
- // intialize is failed
- return 1;
- }
-
- if(net_nfc_deinitialize() == NET_NFC_OK){
- // deinitialize is success
- }
-
- return 0;
- }
-
- @endcode
-
-*/
-net_nfc_error_e net_nfc_deinitialize(void);
-
-/**
- You should register callback before calling the asyn functions.
- All of result comes from callback function, such as data of read operation,
- Target infomation and the event of async operation completions.
- you can replace callback or user_parameter any time by calling this function.
- callback resgister's user_parameter is used only if the event does not have owner.
- most of event gerenrated by calling async APIs, but detection event, detatch
- event, and etc does not have event owner. These events return the user_param
- in the callback function
- if you call this function when the callback function is already registered, it replaces
- the new callback and user_param.
-
- @param[in] cb callback function
- @param[in] user_param userdata that will be delivered when the event does not have owner
-
- @return return the result of the calling this function
-
- @code
- void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- switch(message)
- {
- ......
- default:
- break;
- }
- }
-
- @exception NET_NFC_NULL_PARAMETER Null parameter is received
-
- int main()
- {
-
- net_nfc_error_e result;
- result = net_nfc_initialize();
- check_result(result);
-
- result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);
- check_result(result);
-
- return 0;
- }
-
- @endcode
-
-*/
-net_nfc_error_e net_nfc_set_response_callback(net_nfc_response_cb cb, void *user_param);
-
-/**
- this function unregsiters the callback function.
-
- @return return the result of the calling this function
-
- @exception NET_NFC_NOT_REGISTERED unset is requested but the callback was not registered before
-
- @code
- int main()
- {
-
- net_nfc_error_e result;
- result = net_nfc_initialize();
- check_result(result);
-
- result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);
- check_result(result);
-
- net_nfc_unset_response_callback ();
- return 0;
- }
- @endcode
-*/
-net_nfc_error_e net_nfc_unset_response_callback(void);
-
-/**
- this function enables/disables the app select popup.
- If you use this function to block popup, you should allow that when your app is closed.
-
- @param[in] enable enable or disable
-
- @return return the result of the calling this function
-
- @code
- int main()
- {
- net_nfc_error_e result;
- result = net_nfc_initialize();
- check_result(result);
-
- // block app launch popup
- result = net_nfc_set_launch_popup_state(FALSE);
- check_result(result);
-
- // allow app launch popup
- result = net_nfc_set_launch_popup_state(TRUE);
- check_result(result);
-
- return 0;
- }
- @endcode
-*/
-net_nfc_error_e net_nfc_set_launch_popup_state(int enable);
-
-/**
- this function get state of the app select popup.
- If you use this function to block popup, you should allow that when your app is closed.
-
- @return true on enabled, otherwise false.
-
- @code
- int main()
- {
- return net_nfc_get_launch_popup_state();
- }
- @endcode
-*/
-net_nfc_error_e net_nfc_get_launch_popup_state(int *state);
-
-
-/**
- this function on/off the nfc module.
-
- @param[in] state nfc on or off
-
- @return return the result of the calling this function
-
- @code
- int main()
- {
- net_nfc_error_e result;
-
- // nfc module on
- result = net_nfc_set_state(TRUE);
- check_result(result);
-
- result = net_nfc_initialize();
- check_result(result);
-
- // do something
-
- result = net_nfc_deinitialize();
- check_result(result);
-
- // nfc module off
- result = net_nfc_set_state(FALSE);
- check_result(result);
-
- return 0;
- }
- @endcode
-*/
-net_nfc_error_e net_nfc_set_state(int state, net_nfc_set_activation_completed_cb callback);
-
-/**
- this function returns the nfc module state.
-
- @param[out] state nfc on or off
-
- @return return the result of the calling this function
-
- @code
- int main()
- {
- net_nfc_error_e result;
- int state;
-
- result = net_nfc_get_state(&state);
- check_result(result);
-
- if (state == FALSE)
- {
- // nfc module on
- result = net_nfc_set_state(TRUE);
- check_result(result);
- }
-
- result = net_nfc_initialize();
- check_result(result);
-
- return 0;
- }
- @endcode
-*/
-net_nfc_error_e net_nfc_get_state(int *state);
-
-/**
- this function returns the nfc supported or not.
-
- @param[out] state nfc on or off
-
- @return return the result of the calling this function
-
- @code
- int main()
- {
- net_nfc_error_e result;
- int state;
-
- result = net_nfc_is_supported(&state);
- check_result(result);
-
- if (state == FALSE)
- {
- // nfc module on
- result = net_nfc_is_supported(TRUE);
- check_result(result);
- }
-
-
- return 0;
- }
- @endcode
-*/
-net_nfc_error_e net_nfc_is_supported(int *state);
-
-
-/* THIS API is temp for multiple client */
-
-net_nfc_error_e net_nfc_state_activate(void);
-net_nfc_error_e net_nfc_state_deactivate(void);
-
-/**
-@} */
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
-
+#ifndef __NET_NFC_H__
+#define __NET_NFC_H__
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_data.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_ndef_record.h"
+#include "net_nfc_sign_record.h"
+#include "net_nfc_ndef_message_handover.h"
+
+#include "net_nfc_client_context.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_system_handler.h"
+#include "net_nfc_client_transceive.h"
+#include "net_nfc_client_tag.h"
+#include "net_nfc_client_ndef.h"
+#include "net_nfc_client_llcp.h"
+#include "net_nfc_client_p2p.h"
+#include "net_nfc_client_snep.h"
+#include "net_nfc_client_exchanger.h"
+#include "net_nfc_client_handover.h"
+#include "net_nfc_client_se.h"
+#include "net_nfc_client_tag_felica.h"
+#include "net_nfc_client_tag_jewel.h"
+#include "net_nfc_tag_mifare.h"
+#include "net_nfc_client_test.h"
+
+#endif //__NET_NFC_H__
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#ifndef __NET_NFC_CLIENT_H__
+#define __NET_NFC_CLIENT_H__
-#ifndef NET_NFC_SERVICE_TEST_PRIVATE_H
-#define NET_NFC_SERVICE_TEST_PRIVATE_H
+#include <glib.h>
-#include "net_nfc_typedef_private.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* TODO : change to internal header */
+void net_nfc_client_gdbus_init(void);
-void net_nfc_service_test_sim_test(net_nfc_request_msg_t *msg);
-void net_nfc_service_test_get_firmware_version(net_nfc_request_msg_t *msg);
-void net_nfc_service_test_prbs_test(net_nfc_request_msg_t *msg);
-void net_nfc_service_test_set_eedata(net_nfc_request_msg_t *msg);
+void net_nfc_client_gdbus_deinit(void);
+GVariant *net_nfc_client_gdbus_get_privilege();
+
+#ifdef __cplusplus
+}
#endif
+
+#endif //__NET_NFC_CLIENT_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_CONTEXT_H__
+#define __NET_NFC_CLIENT_CONTEXT_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NET_NFC_SERVICE_EMPTY_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/empty"
+#define NET_NFC_SERVICE_WELL_KNOWN_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/wellknown"
+#define NET_NFC_SERVICE_EXTERNAL_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/external"
+#define NET_NFC_SERVICE_MIME_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/mime"
+#define NET_NFC_SERVICE_URI_TYPE \
+ "http://tizen.org/appcontrol/operation/nfc/uri"
+
+
+net_nfc_error_e net_nfc_client_initialize();
+
+net_nfc_error_e net_nfc_client_deinitialize();
+
+net_nfc_error_e net_nfc_client_is_nfc_supported(int *state);
+
+net_nfc_error_e net_nfc_client_get_nfc_state(int *state);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_CONTEXT_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_CLIENT_DISPATCHER_H
-#define NET_NFC_CLIENT_DISPATCHER_H
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_private.h"
-
-#ifdef USE_GLIB_MAIN_LOOP
-void net_nfc_client_call_dispatcher_in_g_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg);
-#elif USE_ECORE_MAIN_LOOP
-void net_nfc_client_call_dispatcher_in_ecore_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg);
-#else
-void net_nfc_client_call_dispatcher_in_current_context(net_nfc_response_cb client_cb, net_nfc_response_msg_t* msg);
-#endif
-net_nfc_error_e net_nfc_client_dispatch_sync_response(net_nfc_response_msg_t *msg);
-
-#endif
-
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __SLP_NET_NFC_EXCHANGER_H__
-#define __SLP_NET_NFC_EXCHANGER_H__
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_EXCHANGER_H__
+#define __NET_NFC_CLIENT_EXCHANGER_H__
#include "net_nfc_typedef.h"
@exception NET_NFC_ALLOC_FAIL memory allocation is failed
@exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
*/
-net_nfc_error_e net_nfc_create_exchanger_data(net_nfc_exchanger_data_h *ex_data, data_h payload);
+net_nfc_error_e net_nfc_client_create_exchanger_data(
+ net_nfc_exchanger_data_h *ex_data,
+ data_h payload);
+
/**
this makes free exchagner data handler
@exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
+net_nfc_error_e net_nfc_client_free_exchanger_data (
+ net_nfc_exchanger_data_h ex_data);
-net_nfc_error_e net_nfc_free_exchanger_data (net_nfc_exchanger_data_h ex_data);
+net_nfc_error_e net_nfc_client_unset_exchanger_cb();
-net_nfc_error_e net_nfc_send_exchanger_data (net_nfc_exchanger_data_h ex_handle, net_nfc_target_handle_h target_handle, void* trans_param);
+
+net_nfc_error_e net_nfc_client_send_exchanger_data (
+ net_nfc_exchanger_data_h ex_handle,
+ net_nfc_target_handle_h target_handle,
+ void* trans_param);
/**
request connection handover with discovered P2P device
@exception NET_NFC_ALLOC_FAIL memory allocation is failed
@exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
-net_nfc_error_e net_nfc_exchanger_request_connection_handover(net_nfc_target_handle_h target_handle, net_nfc_conn_handover_carrier_type_e type);
+net_nfc_error_e net_nfc_client_exchanger_request_connection_handover(
+ net_nfc_target_handle_h target_handle,
+ net_nfc_conn_handover_carrier_type_e type);
/**
get alternative carrier type from connection handover information handle.
@exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
-net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_type(net_nfc_connection_handover_info_h info_handle, net_nfc_conn_handover_carrier_type_e *type);
+net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_type(
+ net_nfc_connection_handover_info_h info_handle,
+ net_nfc_conn_handover_carrier_type_e *type);
/**
get alternative carrier dependant data from connection handover information handle.
@exception NET_NFC_ALLOC_FAIL memory allocation is failed
@exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
-net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle, data_h *data);
+net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle,
+ data_h *data);
/**
this makes free alternative carrier data handler
@exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
-net_nfc_error_e net_nfc_exchanger_free_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle);
+net_nfc_error_e net_nfc_client_exchanger_free_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle);
/**
@}
-
*/
#endif
-#endif
+#endif //__NET_NFC_CLIENT_EXCHANGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_HANDOVER_H__
+#define __NET_NFC_CLIENT_HANDOVER_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_p2p_connection_handover_completed_cb)(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e carrier,
+ data_h ac_data,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_handover_free_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle);
+
+
+net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type(
+ net_nfc_connection_handover_info_h info_handle,
+ net_nfc_conn_handover_carrier_type_e *type);
+
+
+net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle,
+ data_h *data);
+
+
+net_nfc_error_e net_nfc_client_p2p_connection_handover(
+ net_nfc_target_handle_h handle,
+ net_nfc_conn_handover_carrier_type_e arg_type,
+ net_nfc_p2p_connection_handover_completed_cb callback,
+ void *cb_data);
+
+
+net_nfc_error_e net_nfc_client_p2p_connection_handover_sync(
+ net_nfc_target_handle_h handle,
+ net_nfc_conn_handover_carrier_type_e arg_type,
+ net_nfc_conn_handover_carrier_type_e *out_carrier,
+ data_h *out_ac_data);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_handover_init(void);
+
+void net_nfc_client_handover_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_HANDOVER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_CLIENT_IPC_H
-#define NET_NFC_CLIENT_IPC_H
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_util_ipc.h"
-
-net_nfc_error_e net_nfc_client_socket_initialize();
-void net_nfc_client_socket_finalize();
-bool net_nfc_client_is_connected();
-
-net_nfc_error_e net_nfc_client_send_request(net_nfc_request_msg_t *msg, ...);
-net_nfc_error_e net_nfc_client_send_request_sync(net_nfc_request_msg_t *msg, ...);
-
-void _net_nfc_client_set_cookies(const char * cookie, size_t size);
-void _net_nfc_client_free_cookies(void);
-
-net_nfc_error_e _net_nfc_client_register_cb(net_nfc_response_cb cb);
-net_nfc_error_e _net_nfc_client_unregister_cb(void);
-
-#endif
-
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_LLCP_H__
+#define __NET_NFC_CLIENT_LLCP_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_llcp_config_completed) (net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_listen_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_connect_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_connect_sap_completed) (
+ net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_send_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_send_to_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_receive_completed) (net_nfc_error_e result,
+ data_h data,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_receive_from_completed) (
+ net_nfc_error_e result,
+ sap_t sap,
+ data_h data,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_close_completed) (net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+typedef void (*net_nfc_client_llcp_disconnect_completed) (
+ net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_h config,
+ net_nfc_client_llcp_config_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_config_sync
+ (net_nfc_llcp_config_info_h config);
+
+net_nfc_error_e net_nfc_client_llcp_get_config
+ (net_nfc_llcp_config_info_h *config);
+
+net_nfc_error_e net_nfc_client_llcp_listen(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ sap_t sap,
+ net_nfc_client_llcp_listen_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_listen_sync(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ sap_t sap,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_connect(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ net_nfc_client_llcp_connect_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_connect_sync(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_send(net_nfc_llcp_socket_t socket,
+ data_h data,
+ net_nfc_client_llcp_send_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_send_sync(net_nfc_llcp_socket_t socket,
+ data_h data,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ data_h data,
+ net_nfc_client_llcp_send_to_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_send_to_sync(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ data_h data,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_receive(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ net_nfc_client_llcp_receive_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_receive_sync(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ data_h *out_data);
+
+net_nfc_error_e net_nfc_client_llcp_receive_from(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ net_nfc_client_llcp_receive_from_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_receive_from_sync(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ sap_t *out_sap,
+ data_h *out_data);
+
+net_nfc_error_e net_nfc_client_llcp_close(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_close_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_close_sync(net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_t *out_socket);
+
+net_nfc_error_e net_nfc_client_llcp_disconnect(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_disconnect_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_disconnect_sync(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_t *out_socket);
+
+void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket,
+ net_nfc_llcp_socket_option_h option);
+
+net_nfc_error_e net_nfc_client_llcp_get_local_config(
+ net_nfc_llcp_config_info_h *config);
+
+net_nfc_error_e net_nfc_client_llcp_get_local_socket_option(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_option_h *option);
+
+net_nfc_error_e net_nfc_client_llcp_create_socket_option(
+ net_nfc_llcp_socket_option_h *option,
+ uint16_t miu,
+ uint8_t rw,
+ net_nfc_socket_type_e type);
+
+net_nfc_error_e net_nfc_client_llcp_socket_option_default(
+ net_nfc_llcp_socket_option_h *option);
+
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_miu(
+ net_nfc_llcp_socket_option_h option,
+ uint16_t *miu);
+
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_miu(
+ net_nfc_llcp_socket_option_h option,
+ uint16_t miu);
+
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_rw(
+ net_nfc_llcp_socket_option_h option,
+ uint8_t *rt);
+
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_rw(
+ net_nfc_llcp_socket_option_h option,
+ uint8_t rt);
+
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_type(
+ net_nfc_llcp_socket_option_h option,
+ net_nfc_socket_type_e *type);
+
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_type(
+ net_nfc_llcp_socket_option_h option,
+ net_nfc_socket_type_e type);
+
+net_nfc_error_e net_nfc_client_llcp_free_socket_option(
+ net_nfc_llcp_socket_option_h option);
+
+net_nfc_error_e net_nfc_client_llcp_create_config(
+ net_nfc_llcp_config_info_h *config,
+ uint16_t miu,
+ uint16_t wks,
+ uint8_t lto,
+ uint8_t option);
+
+net_nfc_error_e net_nfc_client_llcp_create_config_default(
+ net_nfc_llcp_config_info_h *config);
+
+net_nfc_error_e net_nfc_client_llcp_get_config_miu(
+ net_nfc_llcp_config_info_h config,
+ uint16_t *miu);
+
+net_nfc_error_e net_nfc_client_llcp_get_config_wks(
+ net_nfc_llcp_config_info_h config,
+ uint16_t *wks);
+
+net_nfc_error_e net_nfc_client_llcp_get_config_lto(
+ net_nfc_llcp_config_info_h config,
+ uint8_t *lto);
+
+net_nfc_error_e net_nfc_client_llcp_get_config_option(
+ net_nfc_llcp_config_info_h config,
+ uint8_t *option);
+
+net_nfc_error_e net_nfc_client_llcp_set_config_miu(
+ net_nfc_llcp_config_info_h config,
+ uint16_t miu);
+
+net_nfc_error_e net_nfc_client_llcp_set_config_wks(
+ net_nfc_llcp_config_info_h config,
+ uint16_t wks);
+
+net_nfc_error_e net_nfc_client_llcp_set_config_lto(
+ net_nfc_llcp_config_info_h config,
+ uint8_t lto);
+
+net_nfc_error_e net_nfc_client_llcp_set_config_option(
+ net_nfc_llcp_config_info_h config,
+ uint8_t option);
+
+net_nfc_error_e net_nfc_client_llcp_free_config(
+ net_nfc_llcp_config_info_h config);
+
+net_nfc_error_e net_nfc_client_llcp_create_socket_option_default(
+ net_nfc_llcp_socket_option_h *option);
+
+net_nfc_error_e net_nfc_client_llcp_connect_sap(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ net_nfc_client_llcp_connect_sap_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_llcp_connect_sap_sync(
+ net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ net_nfc_llcp_socket_t *out_socket);
+
+
+net_nfc_error_e net_nfc_client_llcp_init(void);
+
+void net_nfc_client_llcp_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_LLCP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_MANAGER_H__
+#define __NET_NFC_CLIENT_MANAGER_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_manager_set_active_completed)(
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_manager_get_server_state_completed)(
+ net_nfc_error_e result,
+ unsigned int state,
+ void *user_data);
+
+typedef void (*net_nfc_client_manager_activated)(bool state,
+ void *user_data);
+
+void net_nfc_client_manager_set_activated(
+ net_nfc_client_manager_activated callback,
+ void *user_data);
+
+void net_nfc_client_manager_unset_activated(void);
+
+net_nfc_error_e net_nfc_client_manager_set_active(int state,
+ net_nfc_client_manager_set_active_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_manager_set_active_sync(int state);
+
+net_nfc_error_e net_nfc_client_manager_get_server_state(
+ net_nfc_client_manager_get_server_state_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_manager_get_server_state_sync(
+ unsigned int *state);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_manager_init(void);
+
+void net_nfc_client_manager_deinit(void);
+
+bool net_nfc_client_manager_is_activated();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_MANAGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_NDEF_H__
+#define __NET_NFC_CLIENT_NDEF_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_ndef_read_completed) (net_nfc_error_e result,
+ ndef_message_h message,
+ void *user_data);
+
+typedef void (*net_nfc_client_ndef_write_completed) (net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_ndef_make_read_only_completed) (
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_ndef_format_completed) (net_nfc_error_e result,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_read(net_nfc_target_handle_h handle,
+ net_nfc_client_ndef_read_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_read_sync(net_nfc_target_handle_h handle,
+ ndef_message_h *message);
+
+net_nfc_error_e net_nfc_client_ndef_write(net_nfc_target_handle_h handle,
+ ndef_message_h message,
+ net_nfc_client_ndef_write_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_write_sync(net_nfc_target_handle_h handle,
+ ndef_message_h message);
+
+net_nfc_error_e net_nfc_client_ndef_make_read_only(
+ net_nfc_target_handle_h handle,
+ net_nfc_client_ndef_make_read_only_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_make_read_only_sync(
+ net_nfc_target_handle_h handle);
+
+net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle,
+ data_h key,
+ net_nfc_client_ndef_format_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_ndef_format_sync(
+ net_nfc_target_handle_h handle,
+ data_h key);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_ndef_init(void);
+
+void net_nfc_client_ndef_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_NDEF_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_CLIENT_NET_NFC_PRIVATE_H__
-#define __NET_NFC_CLIENT_NET_NFC_PRIVATE_H__
-
-#include "net_nfc_typedef_private.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-client_context_t *net_nfc_get_client_context();
-bool net_nfc_tag_is_connected();
-net_nfc_error_e net_nfc_send_init(void *context);
-net_nfc_error_e net_nfc_send_deinit(void *context);
-
-typedef bool (*net_nfc_client_cb)(net_nfc_message_e message, net_nfc_error_e result, void* user_param);
-
-net_nfc_error_e net_nfc_util_release_tag_info(net_nfc_target_info_s *info);
-bool net_nfc_util_check_tag_filter(net_nfc_target_type_e type);
-
-/**
- @} */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_P2P_H__
+#define __NET_NFC_CLIENT_P2P_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* p2p callbacks */
+
+typedef void (*net_nfc_client_p2p_send_completed)(net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_p2p_device_discovered)(net_nfc_target_handle_h handle_info,
+ void *user_data);
+
+typedef void (*net_nfc_client_p2p_device_detached)(void *user_data);
+
+typedef void (*net_nfc_client_p2p_data_received)(
+ data_h p2p_data,
+ void *user_data);
+
+/* P2P client API's*/
+net_nfc_error_e net_nfc_client_p2p_send(net_nfc_exchanger_data_h exchg_data,
+ net_nfc_target_handle_h handle,
+ net_nfc_client_p2p_send_completed callback,
+ void *cb_data);
+
+net_nfc_error_e net_nfc_client_p2p_send_sync(
+ net_nfc_exchanger_data_h exchg_data,
+ net_nfc_target_handle_h handle);
+
+
+/* P2P client API's - used for registering callbacks*/
+void net_nfc_client_p2p_set_data_received(
+ net_nfc_client_p2p_data_received callback,
+ void *user_data);
+
+void net_nfc_client_p2p_set_device_detached(
+ net_nfc_client_p2p_device_detached callback,
+ void *user_data);
+
+void net_nfc_client_p2p_set_device_discovered(
+ net_nfc_client_p2p_device_discovered callback,
+ void *user_data);
+
+/* P2P client API's - used for unregistering callbacks*/
+void net_nfc_client_p2p_unset_data_received(void);
+
+void net_nfc_client_p2p_unset_device_detached(void);
+
+void net_nfc_client_p2p_unset_device_discovered(void);
+
+/* TODO : move to internal header */
+/* Init/Deint function calls*/
+net_nfc_error_e net_nfc_client_p2p_init(void);
+
+void net_nfc_client_p2p_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_P2P_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_SE_H__
+#define __NET_NFC_CLIENT_SE_H__
+
+#include <glib.h>
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*************Secure Element Callbacks*********/
+typedef void (*net_nfc_se_set_se_cb)(
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_se_open_se_cb)(
+ net_nfc_error_e result,
+ net_nfc_target_handle_h handle,
+ void *user_data);
+
+typedef void (*net_nfc_se_close_se_cb)(
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_se_get_atr_cb)(
+ net_nfc_error_e result,
+ data_h data,
+ void *user_data);
+
+typedef void (*net_nfc_se_send_apdu_cb)(
+ net_nfc_error_e result,
+ data_h data,
+ void *user_data);
+
+typedef void (*net_nfc_client_se_event)(
+ net_nfc_message_e event,
+ void *user_data);
+
+typedef void (*net_nfc_client_se_transaction_event)(data_h aid,
+ data_h param,
+ void *user_data);
+
+typedef void (*net_nfc_client_se_ese_detected_event)(
+ net_nfc_target_handle_h handle,
+ int dev_type,
+ data_h data,
+ void *user_data);
+
+/************* Secure Element API's*************/
+
+net_nfc_error_e net_nfc_client_se_set_secure_element_type(
+ net_nfc_se_type_e se_type,
+ net_nfc_se_set_se_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync(
+ net_nfc_se_type_e se_type);
+
+
+net_nfc_error_e net_nfc_client_se_get_secure_element_type(
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync(
+ gint *se_type);
+
+
+net_nfc_error_e net_nfc_client_se_open_internal_secure_element(
+ net_nfc_se_type_e se_type,
+ net_nfc_se_open_se_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync(
+ net_nfc_se_type_e se_type,
+ net_nfc_target_handle_h *handle);
+
+
+net_nfc_error_e net_nfc_client_se_close_internal_secure_element(
+ net_nfc_target_handle_h handle,
+ net_nfc_se_close_se_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync(
+ net_nfc_target_handle_h handle);
+
+
+net_nfc_error_e net_nfc_client_se_get_atr(
+ net_nfc_target_handle_h handle,
+ net_nfc_se_get_atr_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_get_atr_sync(
+ net_nfc_target_handle_h handle,
+ data_h *atr);
+
+
+net_nfc_error_e net_nfc_client_se_send_apdu(
+ net_nfc_target_handle_h handle,
+ data_h apdu_data,
+ net_nfc_se_send_apdu_cb callback,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_se_send_apdu_sync(
+ net_nfc_target_handle_h handle,
+ data_h apdu_data,
+ data_h *response);
+
+
+/************* Secure Element CallBack Register/Deregister functions*************/
+
+void net_nfc_client_se_set_ese_detection_cb(
+ net_nfc_client_se_ese_detected_event callback,
+ void *user_data);
+
+void net_nfc_client_se_unset_ese_detection_cb(void);
+
+void net_nfc_client_se_set_transaction_event_cb(
+ net_nfc_client_se_transaction_event callback,
+ void *user_data);
+
+void net_nfc_client_se_unset_transaction_event_cb(void);
+
+void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback,
+ void *user_data);
+
+void net_nfc_client_se_unset_event_cb(void);
+
+
+/* TODO : move to internal header */
+/************* Secure Element Init/Deint*************/
+
+net_nfc_error_e net_nfc_client_se_init(void);
+
+
+void net_nfc_client_se_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_SE_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_SNEP_H__
+#define __NET_NFC_CLIENT_SNEP_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_snep_event_cb) (
+ net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_start_server(
+ net_nfc_target_handle_h target,
+ const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_start_client(
+ net_nfc_target_handle_h target,
+ const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_send_client_request(
+ net_nfc_snep_handle_h handle,
+ net_nfc_snep_type_t snep_type,
+ ndef_message_h msg,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_send_client_request_sync(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_type_t snep_type,
+ ndef_message_h msg,
+ net_nfc_snep_type_t *resp_type,
+ ndef_message_h *response);
+
+net_nfc_error_e net_nfc_client_snep_stop_service(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_handle_h service,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_stop_service_sync(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_handle_h service);
+
+net_nfc_error_e net_nfc_client_snep_register_server(const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_snep_unregister_server(const char *san,
+ sap_t sap);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_snep_init(void);
+
+void net_nfc_client_snep_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_SNEP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_SYSTEM_HANDLER_H__
+#define __NET_NFC_CLIENT_SYSTEM_HANDLER_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_popup_set_state_callback)(
+ net_nfc_error_e result,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_state(int state,
+ net_nfc_client_popup_set_state_callback callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_state_force(int state,
+ net_nfc_client_popup_set_state_callback callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_state_sync(int state);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_state_force_sync(int state);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state(int enable);
+
+net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force(
+ int enable);
+
+net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state(int *state);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_sys_handler_init(void);
+
+void net_nfc_client_sys_handler_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_SYSTEM_HANDLER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TAG_H__
+#define __NET_NFC_CLIENT_TAG_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_tag_is_tag_connected_completed) (
+ net_nfc_error_e result,
+ net_nfc_target_type_e dev_type,
+ void *user_data);
+
+typedef void (*net_nfc_client_tag_get_current_tag_info_completed) (
+ net_nfc_error_e result,
+ net_nfc_target_info_h info,
+ void *user_data);
+
+typedef void (*net_nfc_client_tag_get_current_target_handle_completed) (
+ net_nfc_error_e result,
+ net_nfc_target_handle_h handle,
+ void *user_data);
+
+typedef void (*net_nfc_client_tag_tag_discovered) (net_nfc_target_info_h info,
+ void *user_data);
+
+typedef void (*net_nfc_client_tag_tag_detached) (void *user_data);
+
+
+net_nfc_error_e net_nfc_client_tag_is_tag_connected(
+ net_nfc_client_tag_is_tag_connected_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_tag_is_tag_connected_sync(
+ net_nfc_target_type_e *dev_type);
+
+net_nfc_error_e net_nfc_client_tag_get_current_tag_info(
+ net_nfc_client_tag_get_current_tag_info_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_tag_get_current_tag_info_sync(
+ net_nfc_target_info_h *info);
+
+net_nfc_error_e net_nfc_client_tag_get_current_target_handle(
+ net_nfc_client_tag_get_current_target_handle_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_tag_get_current_target_handle_sync(
+ net_nfc_target_handle_h *handle);
+
+void net_nfc_client_tag_set_tag_discovered(
+ net_nfc_client_tag_tag_discovered callback,
+ void *user_data);
+
+void net_nfc_client_tag_unset_tag_discovered(void);
+
+void net_nfc_client_tag_set_tag_detached(
+ net_nfc_client_tag_tag_detached callback,
+ void *user_data);
+
+void net_nfc_client_tag_unset_tag_detached(void);
+
+void net_nfc_client_tag_set_filter(net_nfc_event_filter_e filter);
+
+net_nfc_event_filter_e net_nfc_client_tag_get_filter(void);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_tag_init(void);
+
+void net_nfc_client_tag_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_TAG_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TAG_FELICA_H__
+#define __NET_NFC_CLIENT_TAG_FELICA_H__
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_client_transceive.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_TAG
+ @{
+
+ send poll request to felica tag.
+ Use this command to acquire and identify a card. Acqusition of IDm and PMm is possible with this command.
+ By specifying a request code , you can acquire system code or communication performance of the system.
+ By specifying a time slot, you can designate the maximum number of time slots possible to return response.
+
+ NET_NFC_FELICA_POLL_NO_REQUEST = 0x00
+ NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST = 0x01
+ NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST= 0x02
+
+ time slot
+
+ Time slot Max number of slots
+ 0x00, 1
+ 0x01, 2
+ 0x03, 4
+ 0x07, 8
+ 0x0f, 16
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] req_code request code with this command
+ @param[in] time_slot time slot value
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (SYSTEM_CODE, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_poll(net_nfc_target_handle_h handle,
+ net_nfc_felica_poll_request_code_e req_code,
+ uint8_t time_slote,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to check for the existence of Area / Service specified by Area Code / Service Code
+ If the specified Area / Service exists, the card returns version information of the key known as "Key Version" (2 Bytes)
+ If the specified Area / Service does not exist, the card returns 0xffff as it s Key Version
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] number_of_area_service the number of specified Area / Service list
+ @param[in] area_service_list specified Area / Service list
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_request_service(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_area_service,
+ uint16_t area_service_list[],
+ uint8_t number_of_services,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to check whether a card exist
+ the Current mode of the card is returned.
+
+ Mode
+
+ 0x00 Mode0
+ 0x01 Mode1
+ 0x02 Mode2
+ 0x03 Mode3
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_request_response(
+ net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to read block data from a Service that requires no authentification
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] number_of_service the number of service list to read
+ @param[in] service_list specified Service list to read
+ @param[in] number_of_blocks the number of blocks to read
+ @param[in] block_list the blocks to read
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_read_without_encryption(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_services,
+ uint16_t service_list[],
+ uint8_t number_of_blocks,
+ uint8_t block_list[],
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to write block data to a Service that requires no authentification
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] number_of_service the number of service list to write
+ @param[in] service_list specified Service list to write
+ @param[in] number_of_blocks the number of blocks to write
+ @param[in] block_list the blocks to write
+ @param[in] data the data to write
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value, the data length to write is exceed the limitation. It should be less than number_of_blocks * 16 bytes
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_write_without_encryption(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_services,
+ uint16_t service_list[],
+ uint8_t number_of_blocks,
+ uint8_t block_list[],
+ data_h data,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ Use this command to acquire system code of the system located on a card
+ If a card is divided into mutiple system, this command acquires system code of all the system existing in the card
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
+ @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct.
+
+*/
+
+net_nfc_error_e net_nfc_client_felica_request_system_code(
+ net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void* trans_param);
+
+/**
+@}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_CLIENT_TAG_FELICA_H__
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#ifndef __NET_NFC_CLIENT_TAG_INTERNAL_H__
+#define __NET_NFC_CLIENT_TAG_INTERNAL_H__
-#ifndef NET_NFC_TEST_H_
-#define NET_NFC_TEST_H_
+#include <glib.h>
+
+#include "net_nfc_typedef_internal.h"
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
-#include "net_nfc_typedef.h"
-
-net_nfc_error_e net_nfc_sim_test(void);
-net_nfc_error_e net_nfc_prbs_test(int tech, int rate);
-
-net_nfc_error_e net_nfc_get_firmware_version(void);
-
-void net_nfc_test_read_test_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data);
-void net_nfc_test_sim_test_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data);
+gboolean net_nfc_client_tag_is_connected(void);
-net_nfc_error_e net_nfc_set_eedata_register(int mode, int reg_id, uint8_t *data, uint32_t len);
+net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void);
#ifdef __cplusplus
}
#endif
-#endif /* NET_NFC_TEST_H_ */
+#endif //__NET_NFC_CLIENT_TAG_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TAG_JEWEL_H__
+#define __NET_NFC_CLIENT_TAG_JEWEL_H__
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_client_transceive.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+
+ @addtogroup NET_NFC_MANAGER_TAG
+ @{
+
+ read uid from jewel tag.
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ read one byte of specific address .
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] block block number. (block 0 ~ block E)
+ @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+/**
+ read all byte from tag .
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+
+net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+
+/**
+ operate erase and write cycle . If any of BLOCK-0 to BLOCK-D is locked then write with erase is barred form thoes blocks.
+ Additionally 0, D, E blocks are automatically in the lock condition. so write with erase is always barred from thoes blocks.
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] block block number. (block 0 ~ block E)
+ @param[in] data the data to write
+ @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_jewel_write_with_erase(
+ net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ uint8_t data,
+ nfc_transceive_callback callback,
+ void *user_data);
+
+
+/**
+ operate no erase and write cycle .
+
+ The WRITE-NE command is available for three main purposes
+ - Lock . to set the ��lock bit�� for a block
+ - OTP . to set One-Time-Programmable bits (bytes 2 . 7 of Block-E), where between one and eight OTP bits can be set with a singleWRITE-NE command
+ - A fast-write in order to reduce overall time to write data to memory blocks for the first time given that the original condition of memory is zero
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] block block number. (block 0 ~ block E)
+ @param[in] data the data to write
+ @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+
+*/
+
+net_nfc_error_e net_nfc_client_jewel_write_with_no_erase(
+ net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ uint8_t data,
+ nfc_transceive_callback callback,
+ void *user_data);
+
+/**
+@}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__NET_NFC_CLIENT_TAG_JEWEL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TEST_H__
+#define __NET_NFC_CLIENT_TEST_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*net_nfc_client_test_sim_test_completed) (net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_test_prbs_test_completed) (
+ net_nfc_error_e result,
+ void *user_data);
+
+typedef void (*net_nfc_client_test_get_firmware_version_completed) (
+ net_nfc_error_e result,
+ char *version,
+ void *user_data);
+typedef void (*net_nfc_client_test_set_ee_data_completed) (
+ net_nfc_error_e result,
+ void *user_data);
+
+
+net_nfc_error_e net_nfc_client_test_sim_test(
+ net_nfc_client_test_sim_test_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_test_sim_test_sync(void);
+
+net_nfc_error_e net_nfc_client_test_prbs_test(uint32_t tech,
+ uint32_t rate,
+ net_nfc_client_test_prbs_test_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_test_prbs_test_sync(uint32_t tech,
+ uint32_t rate);
+
+net_nfc_error_e net_nfc_client_test_get_firmware_version(
+ net_nfc_client_test_get_firmware_version_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_test_get_firmware_version_sync(char **version);
+
+net_nfc_error_e net_nfc_client_test_set_ee_data(int mode,
+ int reg_id,
+ data_h data,
+ net_nfc_client_test_set_ee_data_completed callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_test_set_ee_data_sync(int mode,
+ int reg_id,
+ data_h data);
+
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_test_init(void);
+
+void net_nfc_client_test_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_TEST_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CLIENT_TRANSCEIVE_H__
+#define __NET_NFC_CLIENT_TRANSCEIVE_H__
+
+#include "net_nfc_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (* nfc_transceive_callback)(net_nfc_error_e result,
+ void *user_data);
+
+typedef void (* nfc_transceive_data_callback)(net_nfc_error_e result,
+ data_h data,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle,
+ data_h rawdata,
+ nfc_transceive_callback callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_h handle,
+ data_h rawdata,
+ nfc_transceive_data_callback callback,
+ void *user_data);
+
+net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_h handle,
+ data_h rawdata);
+
+net_nfc_error_e net_nfc_client_transceive_data_sync(
+ net_nfc_target_handle_h handle,
+ data_h rawdata,
+ data_h *response);
+
+/* TODO : move to internal header */
+net_nfc_error_e net_nfc_client_transceive_init(void);
+
+void net_nfc_client_transceive_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__NET_NFC_CLIENT_TRANSCEIVE_H__
* limitations under the License.
*/
-#ifndef __NET_NFC_SERVER_DISPATCHER__
-#define __NET_NFC_SERVER_DISPATCHER__
+#ifndef __NET_NFC_CLIENT_UTIL_INTERNAL_H__
+#define __NET_NFC_CLIENT_UTIL_INTERNAL_H__
-#include "net_nfc_typedef_private.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
-void net_nfc_dispatcher_queue_push(net_nfc_request_msg_t *req_msg);
-bool net_nfc_dispatcher_start_thread();
-void net_nfc_dispatcher_cleanup_queue(void);
-void net_nfc_dispatcher_put_cleaner(void);
+#ifdef __cplusplus
+}
#endif
+#endif //__NET_NFC_CLIENT_UTIL_INTERNAL_H__
\ No newline at end of file
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <net_nfc_typedef.h>
-
-
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#ifndef __NET_NFC_DATA_H__
#define __NET_NFC_DATA_H__
+#include <net_nfc_typedef.h>
+
#ifdef __cplusplus
extern "C" {
#endif
/**
-@addtogroup NET_NFC_MANAGER_INFO
-@{
- This document is for the APIs reference document
+ @addtogroup NET_NFC_MANAGER_INFO
+ @{
+ This document is for the APIs reference document
- NFC Manager defines are defined in <nfc-manager-def.h>
+ NFC Manager defines are defined in <nfc-manager-def.h>
- @li @c #net_nfc_initialize Initialize the nfc device.
+ @li @c #net_nfc_initialize Initialize the nfc device.
*/
/**
- create data handler only.
+ create data handler only.
- @param[out] data data handler
+ @param[out] data data handler
- @return return the result of this operation
+ @return return the result of this operation
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ */
net_nfc_error_e net_nfc_create_data_only (data_h* data);
/**
- create data handler with initial values, bytes will be copied into the data handler.
+ create data handler with initial values, bytes will be copied into the data handler.
- @param[out] data data handler
- @param[in] bytes binary data
- @param[in] length size of binary data;
+ @param[out] data data handler
+ @param[in] bytes binary data
+ @param[in] length size of binary data;
- @return return the result of this operation
+ @return return the result of this operation
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ */
net_nfc_error_e net_nfc_create_data (data_h* data, const uint8_t* bytes, const uint32_t length);
/**
- get the byes and length from data handler. data handler assume bytes may have '0x0' value.
- that's why this function also provides the length.
+ get the byes and length from data handler. data handler assume bytes may have '0x0' value.
+ that's why this function also provides the length.
- @param[in] data data handler
- @param[out] bytes binary pointer (it returns the direct pointer of handler's data) do not free this
- @param[out] length length of the binary data;
+ @param[in] data data handler
+ @param[out] bytes binary pointer (it returns the direct pointer of handler's data) do not free this
+ @param[out] length length of the binary data;
- @return return the result of this operation
+ @return return the result of this operation
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
net_nfc_error_e net_nfc_get_data (const data_h data, uint8_t** bytes, uint32_t * length);
/**
- replace the data handler with given bytes. binary data (bytes) will be copied to data hander.
- application should free or use local variable for given byte pointer.
+ replace the data handler with given bytes. binary data (bytes) will be copied to data hander.
+ application should free or use local variable for given byte pointer.
- @param[in] data data handler
- @param[in] bytes binary data
- @param[in] length size of binary data
+ @param[in] data data handler
+ @param[in] bytes binary data
+ @param[in] length size of binary data
- @return return the result of this operation
+ @return return the result of this operation
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
net_nfc_error_e net_nfc_set_data (const data_h data, const uint8_t* bytes, const uint32_t length);
/**
- get length of data handler's bytes.
+ get length of data handler's bytes.
- @param[in] data data handler
+ @param[in] data data handler
- @return length of bytes length
+ @return length of bytes length
- @exception 0 is returned if data is NULL
-*/
+ @exception 0 is returned if data is NULL
+ */
uint32_t net_nfc_get_data_length (const data_h data);
/**
- get pointer of the handler's bytes (do not free this. it wll be freed when the application call "net_nfc_free_data" function
+ get pointer of the handler's bytes (do not free this. it wll be freed when the application call "net_nfc_free_data" function
- @param[in] data data handler
+ @param[in] data data handler
- @return the pointer of bytes.
+ @return the pointer of bytes.
- @exception NULL is returned if data is NULL
-*/
+ @exception NULL is returned if data is NULL
+ */
uint8_t * net_nfc_get_data_buffer (const data_h data);
/**
- free data handler. (it also free the copied bytes)
+ free data handler. (it also free the copied bytes)
- @param[in] data data handler
+ @param[in] data data handler
- @return return the result of this operation
+ @return return the result of this operation
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
net_nfc_error_e net_nfc_free_data (data_h data);
}
#endif
-
-#endif
-
+#endif //__NET_NFC_DATA_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __SLP_NET_NFC_EXCHANGER_H__
-#define __SLP_NET_NFC_EXCHANGER_H__
-
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_private.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-net_nfc_exchanger_cb net_nfc_get_exchanger_cb (void);
-
-/**
-@}
-
-*/
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_INTERNAL_SE_H__
-#define __NET_NFC_INTERNAL_SE_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
-
-@addtogroup NET_NFC_MANAGER_SECURE_ELEMENT
-@{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <net_nfc_typedef.h>
-
- @li @c #net_nfc_set_secure_element_type set secure element type
- @li @c #net_nfc_get_secure_element_type get current selected secure element
- @li @c #net_nfc_open_internal_secure_element open selected secure element
- @li @c #net_nfc_open_internal_secure_element_sync open selected secure element (synchronous)
- @li @c #net_nfc_close_internal_secure_element close selected secure element
- @li @c #net_nfc_close_internal_secure_element_sync close selected secure element (synchronous)
- @li @c #net_nfc_send_apdu send apdu to opened secure element
- @li @c #net_nfc_send_apdu_sync send apdu to opened secure element (synchronous)
- @li @c #net_nfc_get_atr request atr of secure element
- @li @c #net_nfc_get_atr_sync request atr of secure element (synchronous)
-*/
-
-/**
- set secure element type. secure element will be a UICC or ESE.
- only one secure element is selected in a time.
- external reader can communicate with secure element by emitting RF
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] se_type secure element type
- @param[in] trans_param user data that will be delivered to callback
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM not supported se_type
-*/
-net_nfc_error_e net_nfc_set_secure_element_type(net_nfc_se_type_e se_type, void *trans_param);
-
-/**
- get current select se type.
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] trans_param user data that will be delivered to callback
-
- @return return the result of the calling the function
-*/
-net_nfc_error_e net_nfc_get_secure_element_type(void *trans_param);
-
-/**
- open and initialize the type of secure element.
- if the type of secure element is selected, then change mode as MODE OFF
- to prevent to be detected by external reader
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] se_type secure element type
- @param[in] trans_param user data that will be delivered to callback
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM not supported se_type
-*/
-net_nfc_error_e net_nfc_open_internal_secure_element(net_nfc_se_type_e se_type, void *trans_param);
-
-/**
- open and initialize the type of secure element.
- if the type of secure element is selected, then change mode as MODE OFF
- to prevent to be detected by external reader
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] se_type secure element type
- @param[out] handle the handle of opened secure element
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM not supported se_type
-*/
-net_nfc_error_e net_nfc_open_internal_secure_element_sync(net_nfc_se_type_e se_type, net_nfc_target_handle_h *handle);
-
-/**
- close opened secure element and change back to previous setting
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] handle the handle of opened secure element
- @param[in] trans_param user data that will be delivered to callback
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM invalid secure element handle
-*/
-net_nfc_error_e net_nfc_close_internal_secure_element(net_nfc_target_handle_h handle, void *trans_param);
-
-/**
- close opened secure element and change back to previous setting
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle the handle of opened secure element
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM invalid secure element handle
-*/
-net_nfc_error_e net_nfc_close_internal_secure_element_sync(net_nfc_target_handle_h handle);
-
-/**
- send apdu to opened secure element
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] handle the handle of opened secure element
- @param[in] apdu apdu command to send
- @param[in] trans_param user data that will be delivered to callback
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM invalid secure element handle
- @exception NET_NFC_NULL_PARAM data is null or empty
-*/
-net_nfc_error_e net_nfc_send_apdu(net_nfc_target_handle_h handle, data_h apdu, void *trans_param);
-
-/**
- send apdu to opened secure element
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] handle the handle of opened secure element
- @param[in] apdu apdu command to send
- @param[out] response result of apdu
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM invalid secure element handle or parameter
- @exception NET_NFC_NULL_PARAM data is null or empty
-*/
-net_nfc_error_e net_nfc_send_apdu_sync(net_nfc_target_handle_h handle, data_h apdu, data_h *response);
-
-/**
- request atr of secure element
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] handle the handle of opened secure element
- @param[in] trans_param user data that will be delivered to callback
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM invalid
-
-*/
-net_nfc_error_e net_nfc_get_atr(net_nfc_target_handle_h handle, void *trans_param);
-
-/**
- request atr of secure element
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle the handle of opened secure element
- @param[out] atr Answer to reset of secure element
-
- @return return the result of the calling the function
-
- @exception NET_NFC_INVALID_PARAM invalid
-
-*/
-net_nfc_error_e net_nfc_get_atr_sync(net_nfc_target_handle_h handle, data_h *atr);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_LLCP_H__
-#define __NET_NFC_LLCP_H__
-
-#include "net_nfc_typedef.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/**
-
-@addtogroup NET_NFC_MANAGER_LLCP
-@{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <nfc-manager-def.h>
-
- @li @c #net_nfc_initialize Initialize the nfc device.
-
-*/
-
-/**
-
- This function creates a socket can handle connection oriented or connectless connection. To create the socket, socket option should be specified.
- The option structure has three attributes.
-
- \par Sync (or) Async: Async
-
- @param[out] socket The socket handler that generated by this function
- @param[in] options This describe the socket types (MIU, RW, Connection type) please, refer the comments
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_create_llcp_socket (net_nfc_llcp_socket_t * socket, net_nfc_llcp_socket_option_h options);
-
-/**
- Register socket callback, this callback should register to get socket activities
- you can register callback any time just after getting socket handler.
- when events is delivered before register callback, all event's will be ignored.
- we recommand register callbac just after create a socket.
-
- @param[in] socket socket handle
- @param[in] cb callback function
- @param[in] user_param user parameter that will be deliver when the callback is called
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
-
-*/
-
-net_nfc_error_e net_nfc_set_llcp_socket_callback (net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_cb cb, void * user_param);
-
-/**
- unregister callback from socket.
-
- @param[in] socket socket handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_NOT_REGISTERED callback was not registered
-*/
-
-net_nfc_error_e net_nfc_unset_llcp_socket_callback (net_nfc_llcp_socket_t socket);
-
-/**
- listen the remote connection with service name and sap number. The service name is a string.
-
- Please, refer SAP values range <br>
- - 00 ~ 15 : Identifies the Well-Known Service Access Points <br>
- - 16 ~ 31 : Identifies Services in the local service environment and are advertised by local SDP <br>
- - 32 ~ 61 : Identifies Services in the local service environment and are NOT advertised by local SDP <br>
-
- please follow well known name prefix
- well known service name should be "urn:nfc:sn:<servicename>"
- external service name "urn:nfc:xsn:<domain>:<servicename>"
-
- @param[in] socket socket handler
- @param[in] service_name service name URI, (maxium length is 256)
- @param[in] sap the sap number that will be bind
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_INSUFFICIENT_STORAGE it reached maximum number of socket.
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_INVALID_STATE interanl error
- @exception NET_NFC_ALREADY_REGISTERED SAP number is already in used
-
-*/
-
-
-net_nfc_error_e net_nfc_listen_llcp (net_nfc_llcp_socket_t socket, const char * service_name , sap_t sap, void * trans_param);
-
-/**
-
- disconnect current connection
-
- @param[in] socket socket handler
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_INVALID_STATE interanl error
- @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected
-
-*/
-
-net_nfc_error_e net_nfc_disconnect_llcp (net_nfc_llcp_socket_t socket , void * trans_param);
-
-/**
- close the socket. if you call the this function before call disconnect, automatically, call disonnection inside socket close
-
- @param[in] socket socket handler
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_INVALID_STATE interanl error
-
-*/
-
-
-net_nfc_error_e net_nfc_close_llcp_socket(net_nfc_llcp_socket_t socket , void * trans_param);
-
-
-/**
- send data to remote device. it return callback event when the sending is completed. This api is for connection oriented socket
-
- @param[in] socket socket handler
- @param[in] data raw data to send to remote device
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_INVALID_STATE interanl error
- @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected
- @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected
-
-*/
-
-net_nfc_error_e net_nfc_send_llcp (net_nfc_llcp_socket_t socket, data_h data , void * trans_param);
-
-
-/**
- recieve data from remote device, received data will be delivered in callback function,
- cast the data pointer into "data_h". This api is for connection oriented socket.
-
- @param[in] socket socket handler
- @param[in] req_length length of data will be read
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_INVALID_STATE interanl error
- @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected
- @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected
-*/
-
-net_nfc_error_e net_nfc_receive_llcp (net_nfc_llcp_socket_t socket, size_t req_length, void * trans_param);
-
-
-
-/**
- send data to remote device. it return callback event when the sending is completed.
- this API is for connectionless socket
-
- @param[in] socket socket handler
- @param[in] data raw data to send to remote device
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_INVALID_STATE interanl error
- @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected
- @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected
-*/
-
-net_nfc_error_e net_nfc_send_to_llcp (net_nfc_llcp_socket_t socket,sap_t dsap, data_h data , void * trans_param);
-
-
-/**
- recieve data from remote device, received data will be delivered in callback function,
- cast the data pointer into "data_h".
- this API is for connectionless socket
-
- @param[in] socket socket handler
- @param[in] req_length length of data will be read
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_INVALID_STATE interanl error
- @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected
- @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected
- @exception NET_NFC_ALREADY_REGISTERED SAP number is already in used
-*/
-
-net_nfc_error_e net_nfc_receive_from_llcp (net_nfc_llcp_socket_t socket, sap_t ssap, size_t req_length, void * trans_param);
-
-
-/**
- connect to the remote device with destiantion sap number you should know the sap number (0 ~ 61)
-
- @param[in] socket socket handler
- @param[in] sap sap (Service Access Point) of remote device
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_INVALID_STATE interanl error
- @exception NET_NFC_LLCP_SOCKET_FRAME_REJECTED requested data is rejected
- @exception NET_NFC_LLCP_SOCKET_DISCONNECTED socket is disconnected
-*/
-
-net_nfc_error_e net_nfc_connect_llcp_with_sap (net_nfc_llcp_socket_t socket, sap_t sap , void * trans_param);
-
-
-/**
- connect to the remote device's service name.
-
- @param[in] socket socket handler
- @param[in] service_name service name of the
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_INVALID_STATE interanl error
-*/
-
-net_nfc_error_e net_nfc_connect_llcp (net_nfc_llcp_socket_t socket, const char * service_name , void * trans_param);
-
-
-/**
-
- get local infomation of local device. the device infomation can be configurable with "net_nfc_llcp_set_configure" function
-
- @param[out] config configuration info
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-
-net_nfc_error_e net_nfc_get_llcp_local_configure (net_nfc_llcp_config_info_h * config);
-
-/**
-
- get local infomation of remote device.
-
- @param[in] handle target handle that be optained just after the target detect
- @param[out] config configuration handle
-
- @return return the result of the calling the function
-
-*/
-
-net_nfc_error_e net_nfc_get_llcp_remote_configure (net_nfc_target_handle_h handle, net_nfc_llcp_config_info_h * config);
-
-/**
-
- configure the local device's llcp options this function is optional if you didn't configure local device all the value will be set with default values
-
- @param[in] config configuration handle
- @param[in] trans_param user parameter
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-
-net_nfc_error_e net_nfc_set_llcp_local_configure (net_nfc_llcp_config_info_h config , void * trans_param);
-
-/**
- this function return the current local socket options. if you need to know the remote connection's socket
- info please call "net_nfc_llcp_get_remote_socket_option" function
-
- @param[in] socket socket handler
- @param[out] option infomation of the socket
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
-*/
-
-
-net_nfc_error_e net_nfc_get_llcp_local_socket_option (net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * option);
-
-/**
-
- this function return the current remote socket options.
-
- @param[in] socket socket handler
- @param[out] option infomation of the socket
-
- @return return the result of the calling the function
-
- @exception NET_NFC_LLCP_INVALID_SOCKET invalied socket handler is recieved
-*/
-
-net_nfc_error_e net_nfc_get_llcp_remote_socket_option (net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * option);
-
-/**
- this function create the attribtues of socket.
-
- - MIU (Maximum Information Unit) : Maximum size of infomation unit of LLC PDU (you may assume a packet in network system)
- An LLC SHALL NOT send any LLC PDU with an information field that is larger than the Link MIU determined for the remote LLC.
- An LLC MAY discard any received LLC PDU with an information field that is larger than the local LLCs Link MIU value.
- The default value is 128, and range of this value is 128 - 1152 <br>
- - RW (Receive Window Size) : Rnage 1 -15 (default is 1), if the value is 0 it does not accept I PDU's on that data link connection.
- A receive window size of one indicates that the local LLC will acknowledge every I PDU before accepting additional I PDUs.<br>
- - Socket types : two types of socket are connection oriented and connection less. the default value is connection oriented <br>
-
-
- @param[out] option socket option handler
- @param[in] miu Maximum Information Unit
- @param[in] rw Receive Window Size
- @param[in] type socket type (connection oriented or connection less)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_OUT_OF_BOUND given parameter is out of bound
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-
-net_nfc_error_e net_nfc_create_llcp_socket_option (net_nfc_llcp_socket_option_h * option, uint16_t miu, uint8_t rw, net_nfc_socket_type_e type);
-
-/**
- create default socket option handler. this function create handler and set the all of the socket option with default values
- @param[out] option option handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_OUT_OF_BOUND given parameter is out of bound
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-
-net_nfc_error_e net_nfc_create_llcp_socket_option_default (net_nfc_llcp_socket_option_h * option);
-
-/**
- this function help to get miu values from socket option
-
- @param[in] option socket option handle
- @param[out] miu maximum infomation unit
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_get_llcp_socket_option_miu (net_nfc_llcp_socket_option_h option, uint16_t * miu);
-
-/**
- this function help to set miu value to the socket option handle
-
- @param[in] option socket option handle
- @param[out] miu maximum infomation unit
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_set_llcp_socket_option_miu (net_nfc_llcp_socket_option_h option, uint16_t miu);
-
-/**
- this function help to get rt value from the socket option handle
-
- @param[in] option socket option handle
- @param[out] rt receive window size
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_get_llcp_socket_option_rw (net_nfc_llcp_socket_option_h option, uint8_t * rt);
-
-/**
- this function help to set miu value to the socket option handle
-
- @param[in] option socket option handle
- @param[out] rt maximum infomation unit
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-
-*/
-net_nfc_error_e net_nfc_set_llcp_socket_option_rw (net_nfc_llcp_socket_option_h option, uint8_t rt);
-
-/**
- this function help to get socket type value from the socket option handle
-
- @param[in] option socket option handle
- @param[out] type socket type connection oriented or connectionless
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_get_llcp_socket_option_type (net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e * type);
-
-/**
- this function help to set socket type value to the socket option handle
-
- @param[in] option socket option handle
- @param[out] type socket type connection oriented or connectionless
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_set_llcp_socket_option_type (net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e type);
-
-/**
- free the socket option handle
-
- @param[in] option socket option handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
-net_nfc_error_e net_nfc_free_llcp_socket_option (net_nfc_llcp_socket_option_h option);
-
-
- /**
- This function create llcp_config_info handler that contains the llcp configuration.
- After creating this handler and put his configuration "net_nfc_set_llcp_local_configure" function
-
- note:
-
- @param[out] config configuration handler
- @param[in] miu Maximum Information Unit
- @param[in] wks well knwon service (please refer the note to get detail infomation)
- @param[in] lto link time out value
- @param[in] option option bits that describe the service support
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_OUT_OF_BOUND given parameter is out of bound
-
- Note:
- - The WKS parameter SHALL be encoded as a 16-bit field. The most-significant bit of the 16-bit field value SHALL signify
- SAP address 0Fh and the least-significant bit SHALL signify SAP address 00h. The other bits SHALL signify SAP addresses
- corresponding to their respective bit positions. A bit set to ?1? SHALL indicate that a service listener is bound to the corresponding
- well-known service access point. A bit set to ?0? SHALL indicate that no service listener is bound to the corresponding well-known
- service access point.<br>
-
- - The option field contains a single 8-bit byte representing a set of flags which indicate the link service class of
- the sending LLC and the support of optional features implemented by the sending LLC.<br>
- */
- net_nfc_error_e net_nfc_create_llcp_configure (net_nfc_llcp_config_info_h * config,uint16_t miu, uint16_t wks, uint8_t lto, uint8_t option);
-
-
- /**
- this function create config info handle with default values.
-
- @param[out] config configuration handler
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- */
-
- net_nfc_error_e net_nfc_create_llcp_configure_default (net_nfc_llcp_config_info_h * config);
-
- /**
- getting miu value from config info handle
-
- @param[in] config config info handle
- @param[out] miu maxium information unit
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
-
- net_nfc_error_e net_nfc_get_llcp_configure_miu (net_nfc_llcp_config_info_h config, uint16_t * miu);
- /**
- getting wks value from config info handle
-
- @param[in] config config info handle
- @param[out] wks well-known service list
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
- net_nfc_error_e net_nfc_get_llcp_configure_wks (net_nfc_llcp_config_info_h config, uint16_t * wks);
- /**
- getting lto value from config info handle
-
- @param[in] config config info handle
- @param[out] lto link timeout value
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
- net_nfc_error_e net_nfc_get_llcp_configure_lto (net_nfc_llcp_config_info_h config, uint8_t * lto);
- /**
- getting miu value from config info handle
-
- @param[in] config config info handle
- @param[out] option option of socket type supports
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
- net_nfc_error_e net_nfc_get_llcp_configure_option (net_nfc_llcp_config_info_h config, uint8_t * option);
- /**
- setting the miu value to config info handle
-
- @param[in] config config info handle
- @param[in] miu maxium information unit
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND given parameter is out of bound
- */
- net_nfc_error_e net_nfc_set_llcp_configure_miu (net_nfc_llcp_config_info_h config, uint16_t miu);
- /**
- setting the miu value to config info handle
-
- @param[in] config config info handle
- @param[in] wks well-known service list
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
- net_nfc_error_e net_nfc_set_llcp_configure_wks (net_nfc_llcp_config_info_h config, uint16_t wks);
- /**
- setting the miu value to config info handle
-
- @param[in] config config info handle
- @param[in] lto link timeout value
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
- net_nfc_error_e net_nfc_set_llcp_configure_lto (net_nfc_llcp_config_info_h config, uint8_t lto);
- /**
- setting the miu value to config info handle
-
- @param[in] config config info handle
- @param[in] option option of socket type supports
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
- net_nfc_error_e net_nfc_set_llcp_configure_option (net_nfc_llcp_config_info_h config, uint8_t option);
- /**
- free the configuration info
-
- @param[in] config config info handle
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- */
- net_nfc_error_e net_nfc_free_llcp_configure (net_nfc_llcp_config_info_h config);
-
-
- net_nfc_error_e net_nfc_get_current_target_handle(void* trans_param);
- net_nfc_error_e net_nfc_get_current_target_handle_sync(net_nfc_target_handle_h *handle);
-
- /**
-@}
-*/
-
-
-#ifdef __cplusplus
- }
-#endif
-
-
-#endif
-
-
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#ifndef __NET_NFC_NDEF_MESSAGE_H__
#define __NET_NFC_NDEF_MESSAGE_H__
#include "net_nfc_typedef.h"
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
/**
-@addtogroup NET_NFC_MANAGER_NDEF
-@{
- This document is for the APIs reference document
+ @addtogroup NET_NFC_MANAGER_NDEF
+ @{
+ This document is for the APIs reference document
- NFC Manager defines are defined in <nfc-manager-def.h>
+ NFC Manager defines are defined in <nfc-manager-def.h>
- @li @c #net_nfc_initialize Initialize the nfc device.
+ @li @c #net_nfc_initialize Initialize the nfc device.
*/
/**
- create ndef message handler. this function allocate the ndef message handler and initialize.
+ create ndef message handler. this function allocate the ndef message handler and initialize.
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[out] ndef_message instance of the ndef_message is retuened
+ @param[out] ndef_message instance of the ndef_message is retuened
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @code
+ @code
- net_nfc_error_e result = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
- result = net_nfc_create_ndef_message (&msg);
- if (result != NET_NFC_OK) return result;
+ result = net_nfc_create_ndef_message (&msg);
+ if (result != NET_NFC_OK) return result;
- result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
- if (result != NET_NFC_OK) return result;
+ result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ if (result != NET_NFC_OK) return result;
- result = net_nfc_append_record_to_ndef_message (msg ,record);
- if (result != NET_NFC_OK) return result;
+ result = net_nfc_append_record_to_ndef_message (msg ,record);
+ if (result != NET_NFC_OK) return result;
- net_nfc_write_ndef(id, msg, &user_context);
+ net_nfc_write_ndef(id, msg, &user_context);
- net_nfc_free_ndef_message (msg);
+ net_nfc_free_ndef_message (msg);
- @endcode
-*/
+ @endcode
+ */
net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message);
/**
- this APIs is the getter of record counts
+ this APIs is the getter of record counts
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[in] ndef_message output structure to get the record
- @param[out] count number of record count
+ @param[in] ndef_message output structure to get the record
+ @param[out] count number of record count
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @code
+ @code
static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
{
net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count);
/**
- This function converts the NDEF Message structure to serial bytes of ndef message.
+ This function converts the NDEF Message structure to serial bytes of ndef message.
- it gets copy of the rawdata bytes from ndef_message. ndef_message has no effect after free rawdata
- Application should free rawdata.
+ it gets copy of the rawdata bytes from ndef_message. ndef_message has no effect after free rawdata
+ Application should free rawdata.
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[in] ndef_message output structure to get the record
- @param[out] rawdata this is the raw data that will be formed into the
+ @param[in] ndef_message output structure to get the record
+ @param[out] rawdata this is the raw data that will be formed into the
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message
- @code
+ @code
- net_nfc_error_e result = NET_NFC_OK;
- data_h rawdata;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
- int idx;
- uint8_t * buffer = NULL;
+ net_nfc_error_e result = NET_NFC_OK;
+ data_h rawdata;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+ int idx;
+ uint8_t * buffer = NULL;
- result = net_nfc_create_ndef_message (&msg);
- if (result != NET_NFC_OK) return result;
+ result = net_nfc_create_ndef_message (&msg);
+ if (result != NET_NFC_OK) return result;
- result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
- if (result != NET_NFC_OK) return result;
+ result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ if (result != NET_NFC_OK) return result;
- result = net_nfc_append_record_to_ndef_message (msg ,record);
- if (result != NET_NFC_OK) return result;
+ result = net_nfc_append_record_to_ndef_message (msg ,record);
+ if (result != NET_NFC_OK) return result;
- net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
+ net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
- buffer = net_nfc_get_data_buffer (rawdata) ;
+ buffer = net_nfc_get_data_buffer (rawdata) ;
- for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)
- {
+ for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)
+ {
printf (" %02X", buffer[idx]);
if (idx % 16 == 0) printf ("\n");
- }
+ }
- net_nfc_free_ndef_message (msg);
+ net_nfc_free_ndef_message (msg);
- @endcode
+ @endcode
*/
net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata);
/**
- This function return the structure of ndef_message from serial format of ndef message.
- You may say create ndef handler from raw serial bytes
- it cunsumes the bytes array until get the (ME==1). it retunrs error if the bytes array does not have ME flag.
- if the array has two NDEF Message serially (not recursive case - like smart poster). the first NDEF message
- will be converted to ndef_message handler, and other messages will be ignored.
+ This function return the structure of ndef_message from serial format of ndef message.
+ You may say create ndef handler from raw serial bytes
+ it cunsumes the bytes array until get the (ME==1). it retunrs error if the bytes array does not have ME flag.
+ if the array has two NDEF Message serially (not recursive case - like smart poster). the first NDEF message
+ will be converted to ndef_message handler, and other messages will be ignored.
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[out] ndef_message ndef message handler that will be returned
- @param[in] rawdata ndef message that formed in bytes array
+ @param[out] ndef_message ndef message handler that will be returned
+ @param[in] rawdata ndef message that formed in bytes array
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NDEF_BUF_END_WITHOUT_ME Wrong formatted NDEF message
- @code
+ @code
static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
{
net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h rawdata);
/**
- it returns the total size of ndef message bytes. parse the structure data and count the bytes
- to know the length of bytes required to store the NDEF message.
+ it returns the total size of ndef message bytes. parse the structure data and count the bytes
+ to know the length of bytes required to store the NDEF message.
- it calculates the length every time application calls this function. it does not cache inside.
- TODO: do we need to cache the value inside of ndef_message_h
+ it calculates the length every time application calls this function. it does not cache inside.
+ TODO: do we need to cache the value inside of ndef_message_h
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[in] ndef_message this is the raw data that will be formed into the
- @param[out] length number of bytes required to create ndef message serial format
+ @param[in] ndef_message this is the raw data that will be formed into the
+ @param[out] length number of bytes required to create ndef message serial format
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @return return the result of the calling the function
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
-net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, int * length) ;
+net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, uint32_t *length);
/**
- Append a record to ndef message structure.
- This API help to create NDEF message and it control Record flags to follow the NDEF forum specification
-
- \par Sync (or) Async: sync
- This is a Synchronous API
-
- @param[in] ndef_message NDEF message structure
- @param[in] record a record will be added into the ndef message
+ Append a record to ndef message structure.
+ This API help to create NDEF message and it control Record flags to follow the NDEF forum specification
- @return return the result of the calling the function
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @param[in] ndef_message NDEF message structure
+ @param[in] record a record will be added into the ndef message
- @code
+ @return return the result of the calling the function
- net_nfc_error_e result = NET_NFC_OK;
- data_h rawdata;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
- int idx;
- uint8_t * buffer = NULL;
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- result = net_nfc_create_ndef_message (&msg);
- if (result != NET_NFC_OK) return result;
+ @code
- result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
- if (result != NET_NFC_OK) return result;
+ net_nfc_error_e result = NET_NFC_OK;
+ data_h rawdata;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+ int idx;
+ uint8_t * buffer = NULL;
- result = net_nfc_append_record_to_ndef_message (msg ,record);
- if (result != NET_NFC_OK) return result;
+ result = net_nfc_create_ndef_message (&msg);
+ if (result != NET_NFC_OK) return result;
- net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
+ result = net_nfc_create_uri_type_record (&record , "http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ if (result != NET_NFC_OK) return result;
- buffer = net_nfc_get_data_buffer (rawdata) ;
+ result = net_nfc_append_record_to_ndef_message (msg ,record);
+ if (result != NET_NFC_OK) return result;
- for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)
- {
- printf (" %02X", buffer[idx]);
- if (idx % 16 == 0) printf ("\n");
- }
+ net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
- net_nfc_free_ndef_message (msg);
+ buffer = net_nfc_get_data_buffer (rawdata) ;
- @endcode
+ for (idx = 0; idx < net_nfc_get_data_length (rawdata) ; idx++)
+ {
+ printf (" %02X", buffer[idx]);
+ if (idx % 16 == 0) printf ("\n");
+ }
+ net_nfc_free_ndef_message (msg);
+ @endcode
*/
net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record);
/**
- remove the record that indicated by index number.
- and this deleted record will be freed.
+ remove the record that indicated by index number.
+ and this deleted record will be freed.
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[in] ndef_message the message wil be freed
- @param[in] index index of record
+ @param[in] ndef_message the message wil be freed
+ @param[in] index index of record
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND index is out of bound
- @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND index is out of bound
+ @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
*/
net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index);
/**
- get record by index. this function just return the pointer of record.
- if you change the record value it directly affected to NDEF message
+ get record by index. this function just return the pointer of record.
+ if you change the record value it directly affected to NDEF message
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[in] ndef_message the message wil be freed
- @param[in] index index of record
- @param[in] record record pointer
+ @param[in] ndef_message the message wil be freed
+ @param[in] index index of record
+ @param[in] record record pointer
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND index is out of bound
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND index is out of bound
*/
net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h* record);
/**
- Add a record by index. This API help to add record by index. MB or ME bits will automatically assained.
+ Add a record by index. This API help to add record by index. MB or ME bits will automatically assained.
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[in] ndef_message the message wil be freed
- @param[in] index index of record
- @param[in] record record pointer
+ @param[in] ndef_message the message wil be freed
+ @param[in] index index of record
+ @param[in] record record pointer
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND index is out of bound
- @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND index is out of bound
+ @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
+ */
net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message,int index, ndef_record_h record);
/**
- search the specific type in the NDEF message. this function return the first record that holds the type.
- if the type has "urn:nfc:wkt:" or "urn:nfc:ext:", these prefix will be removed automatically.
+ search the specific type in the NDEF message. this function return the first record that holds the type.
+ if the type has "urn:nfc:wkt:" or "urn:nfc:ext:", these prefix will be removed automatically.
- @param[in] ndef_message NDEF message handler
- @param[in] tnf TNF value
- @param[in] type Record type , include type length
- @param[out] record record handle
+ @param[in] ndef_message NDEF message handler
+ @param[in] tnf TNF value
+ @param[in] type Record type , include type length
+ @param[out] record record handle
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND search is failed
- @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND search is failed
+ @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
- @code
+ @code
static void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
{
}
}
- @endcode
+ @endcode
*/
net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, net_nfc_record_tnf_e tnf, data_h type, ndef_record_h * record);
/**
- this function helps to free the ndef_message_s type structure.
- it has multiple ndef_record_s with linked list form and each record has own pointer.
- this function free these memory in one shot!
- don't worry about the record handler. these handlers also freed.
+ this function helps to free the ndef_message_s type structure.
+ it has multiple ndef_record_s with linked list form and each record has own pointer.
+ this function free these memory in one shot!
+ don't worry about the record handler. these handlers also freed.
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[in] ndef_message the message wil be freed
+ @param[in] ndef_message the message wil be freed
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
/**
- retreive ndef message which is read by nfc-manager .
- after reading message, it will be removed from nfc-manager storage
+ retreive ndef message which is read by nfc-manager .
+ after reading message, it will be removed from nfc-manager storage
- \par Sync (or) Async: sync
- This is a Synchronous API
+ \par Sync (or) Async: sync
+ This is a Synchronous API
- @param[in] ndef_message the message wil be retrieved
+ @param[in] ndef_message the message wil be retrieved
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_NDEF_MESSAGE No ndef message is found
- @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_NDEF_MESSAGE No ndef message is found
+ @exception NET_NFC_INVALID_FORMAT Wrong formatted ndef message
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
*/
/**
-@} */
+@}
+*/
#ifdef __cplusplus
}
#endif
-
-#endif
-
+#endif //__NET_NFC_NDEF_MESSAGE_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_NDEF_RECORD_H__
-#define __NET_NFC_NDEF_RECORD_H__
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_NDEF_MESSAGE_HANDOVER_H__
+#define __NET_NFC_NDEF_MESSAGE_HANDOVER_H__
#include "net_nfc_typedef.h"
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
/**
- This function create wifi configure handler instance.
+ This function create wifi configure handler instance.
- @param[out] config instance handler
- @param[in] type Carrier types it would be wifi add hoc or wifi AP
+ @param[out] config instance handler
+ @param[in] type Carrier types it would be wifi add hoc or wifi AP
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND type value is not enum value
- @exception NET_NFC_ALLOC_FAIL allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND type value is not enum value
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type);
/**
- Add property key and value for configuration.
- the data will be copied to config handle, you should free used data array.
+ Add property key and value for configuration.
+ the data will be copied to config handle, you should free used data array.
- @param[in] config instance handler
- @param[in] attribute attribue key for value.
- @param[in] size size of value
- @param[in] data value array (binary type)
+ @param[in] config instance handler
+ @param[in] attribute attribue key for value.
+ @param[in] size size of value
+ @param[in] data value array (binary type)
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
net_nfc_error_e net_nfc_add_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t * data);
/**
- Remove the key and value from configuration, you can also remove the group withe CREDENTIAL key.
- The the attribute is exist then it will be removed and also freed automatically.
+ Remove the key and value from configuration, you can also remove the group withe CREDENTIAL key.
+ The the attribute is exist then it will be removed and also freed automatically.
- @param[in] config instance handler
- @param[in] attribute attribue key for value.
+ @param[in] config instance handler
+ @param[in] attribute attribue key for value.
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND the given key is not found
- @exception NET_NFC_ALREADY_REGISTERED the given attribute is already registered
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND the given key is not found
+ @exception NET_NFC_ALREADY_REGISTERED the given attribute is already registered
+ */
net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute);
/**
- Get the property value by attribute.
+ Get the property value by attribute.
- @param[in] config instance handler
- @param[in] attribute attribue key for value.
- @param[out] size size of value
- @param[out] data value array (binary type)
+ @param[in] config instance handler
+ @param[in] attribute attribue key for value.
+ @param[out] size size of value
+ @param[out] data value array (binary type)
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND The given key is not found
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND The given key is not found
+ */
net_nfc_error_e net_nfc_get_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data);
/**
- The group will be joined into the configure
+ The group will be joined into the configure
- @param[in] config instance handler
- @param[in] group group handle
+ @param[in] config instance handler
+ @param[in] group group handle
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALREADY_REGISTERED The given group is already registered
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALREADY_REGISTERED The given group is already registered
+ */
net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group);
/**
- Remove the group from configure handle
+ Remove the group from configure handle
- @param[in] config instance handler
- @param[in] group group handle
+ @param[in] config instance handler
+ @param[in] group group handle
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND given handle pointer is not exist in the configure handle
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND given handle pointer is not exist in the configure handle
+ */
net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group);
/**
- Get the group from configure handle by index
+ Get the group from configure handle by index
- @param[in] config instance handler
- @param[in] index index number
- @param[out] group group handle
+ @param[in] config instance handler
+ @param[in] index index number
+ @param[out] group group handle
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_OUT_OF_BOUND the index number is not bound of the max count
- @exception NET_NFC_NO_DATA_FOUND this is should be happened if the configure handle is dammaged
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_OUT_OF_BOUND the index number is not bound of the max count
+ @exception NET_NFC_NO_DATA_FOUND this is should be happened if the configure handle is dammaged
+ */
net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group);
/**
- free the configure handle
+ free the configure handle
- @param[in] config instance handler
+ @param[in] config instance handler
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config);
/**
- create the group handle
+ create the group handle
- @param[out] group instance group handler
+ @param[out] group instance group handler
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute);
/**
- add property into the group
+ add property into the group
- @param[in] group instance group handler
- @param[in] attribute attribute of the property
- @param[in] size size of data (value)
- @param[in] data data of the property
+ @param[in] group instance group handler
+ @param[in] attribute attribute of the property
+ @param[in] size size of data (value)
+ @param[in] data data of the property
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_ALREADY_REGISTERED the given key is already registered
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_ALREADY_REGISTERED the given key is already registered
+ */
net_nfc_error_e net_nfc_add_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data);
/**
- get property from group handle
+ get property from group handle
- @param[in] group instance group handler
- @param[in] attribute attribute of the property
- @param[out] size size of data (value)
- @param[out] data data of the property
+ @param[in] group instance group handler
+ @param[in] attribute attribute of the property
+ @param[out] size size of data (value)
+ @param[out] data data of the property
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
+ */
net_nfc_error_e net_nfc_get_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data);
/**
- remove the property from the group
+ remove the property from the group
- @param[in] group instance group handler
- @param[in] attribute attribute of the property
+ @param[in] group instance group handler
+ @param[in] attribute attribute of the property
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
+ */
net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute);
/**
- free the group
+ free the group
- @param[in] group instance group handler
+ @param[in] group instance group handler
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group);
/**
- Create record handler with config.
+ Create record handler with config.
- @param[out] record record handler
- @param[in] config the wifi configure handle
+ @param[out] record record handler
+ @param[in] config the wifi configure handle
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config);
/**
- create configure from the ndef record. the. the record must contained the configuration.
- config should be freed after using
+ create configure from the ndef record. the. the record must contained the configuration.
+ config should be freed after using
- @param[in] record record handler
- @param[out] config the configure handle
+ @param[in] record record handler
+ @param[out] config the configure handle
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ */
net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h* config, ndef_record_h record);
/**
- append record into the connection handover request for reponse message;
+ append record into the connection handover request for reponse message;
- @param[in] message ndef message handler
- @param[in] record record handler
- @param[in] power_status the power status of the current configuration
+ @param[in] message ndef message handler
+ @param[in] record record handler
+ @param[in] power_status the power status of the current configuration
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ @exception NET_NFC_NO_DATA_FOUND the attribute does not exist in the group
+ */
net_nfc_error_e net_nfc_append_carrier_config_record (ndef_message_h message, ndef_record_h record, net_nfc_conn_handover_carrier_state_e power_status);
/**
- append record into the connection handover request for reponse message;
+ append record into the connection handover request for reponse message;
- @param[in] message ndef message handler
- @param[in] record record handler
+ @param[in] message ndef message handler
+ @param[in] record record handler
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- @exception NET_NFC_NO_DATA_FOUND Given record does not exist in the ndef message
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ @exception NET_NFC_NO_DATA_FOUND Given record does not exist in the ndef message
+ */
net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record);
/**
- get configure record from ndef message by index
+ get configure record from ndef message by index
- @param[in] message ndef message handler
- @param[in] index
- @param[out] record record handler
+ @param[in] message ndef message handler
+ @param[in] index
+ @param[out] record record handler
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ */
net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record);
/**
- get randome number from the connection request message
+ get randome number from the connection request message
- @param[in] message ndef message handler
- @param[out] randome_number randome number
+ @param[in] message ndef message handler
+ @param[out] randome_number randome number
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ */
net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number);
/**
- get the count of the alternative (configuration) in the message
+ get the count of the alternative (configuration) in the message
- @param[in] message ndef message handler
- @param[out] count number configuration in the message
+ @param[in] message ndef message handler
+ @param[out] count number configuration in the message
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ */
net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message, unsigned int * count);
/**
- get power status of the given configruation
+ get power status of the given configruation
- @param[in] message ndef message handler
- @param[in] index index
- @param[out] power_state power state of the alternative
+ @param[in] message ndef message handler
+ @param[in] index index
+ @param[out] power_state power state of the alternative
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found
- @exception NET_NFC_OUT_OF_BOUND index number is out of message count
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found
+ @exception NET_NFC_OUT_OF_BOUND index number is out of message count
+ */
net_nfc_error_e net_nfc_get_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state);
/**
- set power status of the given configruation
+ set power status of the given configruation
- @param[in] message ndef message handler
- @param[in] index index
- @param[in] power_state power state of the alternative
+ @param[in] message ndef message handler
+ @param[in] index index
+ @param[in] power_state power state of the alternative
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
- @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found
- @exception NET_NFC_OUT_OF_BOUND index number is out of message count
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_INVALID_FORMAT if the record does not contained the valid format.
+ @exception NET_NFC_NO_DATA_FOUND there is no alternative record is found
+ @exception NET_NFC_OUT_OF_BOUND index number is out of message count
+ */
net_nfc_error_e net_nfc_set_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status);
/**
- this function will get carrier type.
+ this function will get carrier type.
- @param[in] carrier_info connection handover carrier info handler
- @param[in] carrier_type record type. it can be a NET_NFC_CONN_HANDOVER_CARRIER_BT or NET_NFC_CONN_HANDOVER_CARRIER_WIFI or NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN.
+ @param[in] carrier_info connection handover carrier info handler
+ @param[in] carrier_type record type. it can be a NET_NFC_CONN_HANDOVER_CARRIER_BT or NET_NFC_CONN_HANDOVER_CARRIER_WIFI or NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN.
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
net_nfc_error_e net_nfc_get_alternative_carrier_type (ndef_message_h message, int index, net_nfc_conn_handover_carrier_type_e * power_state);
/**
- craete the connection handover request message
+ craete the connection handover request message
- @param[in] message connection handover carrier info handler
+ @param[in] message connection handover carrier info handler
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message);
/**
- craete the connection handover select message
+ craete the connection handover select message
- @param[in] message connection handover carrier info handler
+ @param[in] message connection handover carrier info handler
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message);
/**
- craete the connection handover error record message
+ craete the connection handover error record message
- @param[out] record connection handover carrier info handler
- @param[in] reason error codes (reason)
- @param[in] data extra data for each error codes
+ @param[out] record connection handover carrier info handler
+ @param[in] reason error codes (reason)
+ @param[in] data extra data for each error codes
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL allocation is failed
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL allocation is failed
+ */
net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data);
#ifdef __cplusplus
- }
-#endif
-
-
+}
#endif
+#endif //__NET_NFC_NDEF_MESSAGE_HANDOVER_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#ifndef __NET_NFC_NDEF_RECORD_H__
#define __NET_NFC_NDEF_RECORD_H__
#include "net_nfc_typedef.h"
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
/**
-@addtogroup NET_NFC_MANAGER_RECORD
-@{
- This document is for the APIs reference document
+ @addtogroup NET_NFC_MANAGER_RECORD
+ @{
+ This document is for the APIs reference document
- NFC Manager defines are defined in <nfc-typedef.h>
+ NFC Manager defines are defined in <nfc-typedef.h>
*/
/**
- This define gives you Message Begin from the flag byte
+ This define gives you Message Begin from the flag byte
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the mb flag
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the mb flag
- @exception NONE
-*/
+ @exception NONE
+ */
uint8_t net_nfc_get_record_mb (uint8_t flag);
/**
- This define gives you Message end from the flag byte
+ This define gives you Message end from the flag byte
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the me flag
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the me flag
- @exception NONE
-*/
+ @exception NONE
+ */
uint8_t net_nfc_get_record_me (uint8_t flag);
/**
- This define gives you Chun Flag that indicate that either the first record chunk or a middle record chunk of a chunked payload
+ This define gives you Chun Flag that indicate that either the first record chunk or a middle record chunk of a chunked payload
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the chunk flag
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the chunk flag
- @exception NONE
-*/
+ @exception NONE
+ */
uint8_t net_nfc_get_record_cf (uint8_t flag);
/**
- This define gives you ID length present flag
+ This define gives you ID length present flag
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the il (id length flag) flag
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the il (id length flag) flag
- @exception NONE
+ @exception NONE
*/
uint8_t net_nfc_get_record_il (uint8_t flag);
/**
- This define gives you short record flag. This flag indicates that the payload length filed is a single octet
+ This define gives you short record flag. This flag indicates that the payload length filed is a single octet
- @param[in] flag flag that comes from "net_nfc_get_record_flags" function
- @return the short record flag
+ @param[in] flag flag that comes from "net_nfc_get_record_flags" function
+ @return the short record flag
- @exception NONE
-*/
+ @exception NONE
+ */
uint8_t net_nfc_get_record_sr (uint8_t flag);
/**
- creat a record with given parameter value. this function automatically set the NDEF record flags
+ creat a record with given parameter value. this function automatically set the NDEF record flags
- @param[out] record Record handler
- @param[in] tnf record type (TNF value) empty, well known, mime type, URI, external, or unchanged
- @param[in] typeName specify type name ex) Sp, U, or Hr ...
- @param[in] id record id
- @param[in] payload payload of this record
+ @param[out] record Record handler
+ @param[in] tnf record type (TNF value) empty, well known, mime type, URI, external, or unchanged
+ @param[in] typeName specify type name ex) Sp, U, or Hr ...
+ @param[in] id record id
+ @param[in] payload payload of this record
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_OUT_OF_BOUND tnf value is out of range
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_OUT_OF_BOUND tnf value is out of range
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @code
- char uri[] = " yahoo.com";
- ndef_record_s uriRecord;
+ @code
+ char uri[] = " yahoo.com";
+ ndef_record_s uriRecord;
- data_h payload;
+ data_h payload;
- net_nfc_create_data (&payload, uri, strlen (uri));
- uri[0] = 0x01;
+ net_nfc_create_data (&payload, uri, strlen (uri));
+ uri[0] = 0x01;
- if((result = net_nfc_create_record( &uriRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE, "U" , NULL, payload, )) != NET_NFC_OK)
- {
- printf("U record is failed [%d]\n", result);
- }
- @endcode
-*/
+ if((result = net_nfc_create_record( &uriRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE, "U" , NULL, payload, )) != NET_NFC_OK)
+ {
+ printf("U record is failed [%d]\n", result);
+ }
+ @endcode
+ */
net_nfc_error_e net_nfc_create_record(ndef_record_h* record, net_nfc_record_tnf_e tnf, data_h typeName, data_h id, data_h payload );
/**
- this function helps to create text type payload
- please, refer the NDEF forum specification "Text Record Type Definition"
- it creates byte array payload can be used in text type record
+ this function helps to create text type payload
+ please, refer the NDEF forum specification "Text Record Type Definition"
+ it creates byte array payload can be used in text type record
- this function does not encode the text. The paramter "text" will be asuumed as that it is already encoded with encode type.
- this function just helps to create text records.
+ this function does not encode the text. The paramter "text" will be asuumed as that it is already encoded with encode type.
+ this function just helps to create text records.
- @param[out] record Record handler
- @param[in] text encoded text (this should be text not binary)
- @param[in] language_code_str language_code_str ex) en-US
- @param[in] encode text concoding type such as "utf8"
+ @param[out] record Record handler
+ @param[in] text encoded text (this should be text not binary)
+ @param[in] language_code_str language_code_str ex) en-US
+ @param[in] encode text concoding type such as "utf8"
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @code
- net_nfc_error_e result = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
+ @code
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
- char* message = "Hello, NFC World";
+ char* message = "Hello, NFC World";
- net_nfc_create_ndef_message (&msg);
- net_nfc_create_text_type_record (&record , message, "en-US", NET_NFC_ENCODE_UTF_8);
- net_nfc_append_record_to_ndef_message (msg ,record);
+ net_nfc_create_ndef_message (&msg);
+ net_nfc_create_text_type_record (&record , message, "en-US", NET_NFC_ENCODE_UTF_8);
+ net_nfc_append_record_to_ndef_message (msg ,record);
- @endcode
+ @endcode
*/
net_nfc_error_e net_nfc_create_text_type_record(ndef_record_h* record, const char* text, const char* language_code_str, net_nfc_encode_type_e encode);
/**
- this function helps to create URI type payload
- please refer the NFC forum specification "URI Record type Definition"
- it creates byte array payload.
+ this function helps to create URI type payload
+ please refer the NFC forum specification "URI Record type Definition"
+ it creates byte array payload.
- @param[out] record Record handler
- @param[in] uri string uri that will be stored in the payload
- @param[in] protocol_schema protocol schema that is specified in NFC Forum
+ @param[out] record Record handler
+ @param[in] uri string uri that will be stored in the payload
+ @param[in] protocol_schema protocol schema that is specified in NFC Forum
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @code
- net_nfc_error_e result = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h record = NULL;
+ @code
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
- net_nfc_create_ndef_message (&msg);
- net_nfc_create_uri_type_record (&record ,"http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
- net_nfc_append_record_to_ndef_message (msg ,record);
- @endcode
-*/
+ net_nfc_create_ndef_message (&msg);
+ net_nfc_create_uri_type_record (&record ,"http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ net_nfc_append_record_to_ndef_message (msg ,record);
+ @endcode
+ */
net_nfc_error_e net_nfc_create_uri_type_record(ndef_record_h* record, const char * uri, net_nfc_schema_type_e protocol_schema);
/**
- this function is getter of record payload.
- this function gives you the pointer of pyaload that is contained by record.
- Do not free the payload. it will be freed when the record is freed
+ this function is getter of record payload.
+ this function gives you the pointer of pyaload that is contained by record.
+ Do not free the payload. it will be freed when the record is freed
- @param[in] record Record handler
- @param[out] payload data_h type payload pointer (it gives you the pointer of payload; not copied)
+ @param[in] record Record handler
+ @param[out] payload data_h type payload pointer (it gives you the pointer of payload; not copied)
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_get_record_payload (ndef_record_h record, data_h * payload);
/**
- this function is getter of record type.
- this function gives you the pointer of record type that is contained by record.
- Do not free the type. it will be freed when the record is freed
+ this function is getter of record type.
+ this function gives you the pointer of record type that is contained by record.
+ Do not free the type. it will be freed when the record is freed
- @param[in] record Record handler
- @param[out] type dat_h type pointer (it gives you the pointer of type; not copied)
+ @param[in] record Record handler
+ @param[out] type dat_h type pointer (it gives you the pointer of type; not copied)
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_get_record_type (ndef_record_h record, data_h * type);
/**
- this function is getter of record ID.
- this function gives you the pointer of ID that is contained by record.
- it may return NULL pointer if the ID is not exist
- Do not free the type. it will be freed when the record is freed.
+ this function is getter of record ID.
+ this function gives you the pointer of ID that is contained by record.
+ it may return NULL pointer if the ID is not exist
+ Do not free the type. it will be freed when the record is freed.
- @param[in] record Record handler
- @param[out] id dat_h type ID pointer (it gives you the pointer of payload not copied)
+ @param[in] record Record handler
+ @param[out] id dat_h type ID pointer (it gives you the pointer of payload not copied)
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
-*/
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ */
net_nfc_error_e net_nfc_get_record_id (ndef_record_h record, data_h * id);
/**
- this function is getter of record TNF value.
+ this function is getter of record TNF value.
- @param[in] record Record handler
- @param[out] tnf TNF value
+ @param[in] record Record handler
+ @param[out] tnf TNF value
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_get_record_tnf(ndef_record_h record, net_nfc_record_tnf_e * tnf);
/**
- this function is getter of record flags.
- you can get the each flag value by using defines "RECORD_GET_XX"
+ this function is getter of record flags.
+ you can get the each flag value by using defines "RECORD_GET_XX"
- @param[in] record Record handler
- @param[out] flag flag value (it gives you the pointer of payload not copied)
+ @param[in] record Record handler
+ @param[out] flag flag value (it gives you the pointer of payload not copied)
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @code
+ @code
- ndef_record_h record;
- uint8_t flag;
+ ndef_record_h record;
+ uint8_t flag;
- net_nfc_get_record_by_index (msg, 0, &record);
- if (record != NULL){
- net_nfc_get_record_flags (record, &flag);
- printf ("MB:%d, ME:%d, CF:%d, IL:%d, SR:%d\n",
- net_nfc_get_record_mb(flag),
- net_nfc_get_record_me(flag),
- net_nfc_get_record_cf(flag),
- net_nfc_get_record_il(flag),
- net_nfc_get_record_sr(flag));
- }
+ net_nfc_get_record_by_index (msg, 0, &record);
+ if (record != NULL){
+ net_nfc_get_record_flags (record, &flag);
+ printf ("MB:%d, ME:%d, CF:%d, IL:%d, SR:%d\n",
+ net_nfc_get_record_mb(flag),
+ net_nfc_get_record_me(flag),
+ net_nfc_get_record_cf(flag),
+ net_nfc_get_record_il(flag),
+ net_nfc_get_record_sr(flag));
+ }
- @endcode
+ @endcode
*/
net_nfc_error_e net_nfc_get_record_flags (ndef_record_h record, uint8_t * flag);
/**
- you can set record ID with this function
+ you can set record ID with this function
- @param[in] record Record handler
- @param[in] id Record ID
+ @param[in] record Record handler
+ @param[in] id Record ID
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_set_record_id (ndef_record_h record, data_h id);
/**
- this function free the record handler. do not use this function after appending the ndef message
+ this function free the record handler. do not use this function after appending the ndef message
- @param[in] record Record handler
+ @param[in] record Record handler
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_free_record (ndef_record_h record);
/**
- this function get text from text record. it allocate buffer char and store the text string. you should free this string.
+ this function get text from text record. it allocate buffer char and store the text string. you should free this string.
- @param[in] record Record handler
- @param[out] buffer text string
+ @param[in] record Record handler
+ @param[out] buffer text string
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer);
/**
- this function get language code from text record. (ex: US-en)
+ this function get language code from text record. (ex: US-en)
- @param[in] record Record handler
- @param[out] lang_code_str lang code string value followed by IANA
+ @param[in] record Record handler
+ @param[out] lang_code_str lang code string value followed by IANA
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
/**
- this function get encoding type from text record (ex: UTF-8)
+ this function get encoding type from text record (ex: UTF-8)
- @param[in] record Record handler
- @param[out] encoding encoding type
+ @param[in] record Record handler
+ @param[out] encoding encoding type
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not text record
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
/**
- this function get URI from uri record. you should free the uri string.
+ this function get URI from uri record. you should free the uri string.
- @param[in] record Record handler
- @param[out] uri uri text string
+ @param[in] record Record handler
+ @param[out] uri uri text string
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not uri record
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE record is not uri record
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char ** uri);
#ifdef __cplusplus
- }
-#endif
-
-
+}
#endif
+#endif //__NET_NFC_NDEF_RECORD_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_SIGN_RECORD_H
-#define __NET_NFC_SIGN_RECORD_H
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SIGN_RECORD_H__
+#define __NET_NFC_SIGN_RECORD_H__
#include "net_nfc_typedef.h"
/**
-@addtogroup NET_NFC_MANAGER_RECORD
-@{
- This document is for the APIs reference document
+ @addtogroup NET_NFC_MANAGER_RECORD
+ @{
+ This document is for the APIs reference document
- NFC Manager defines are defined in <nfc-typedef.h>
+ NFC Manager defines are defined in <nfc-typedef.h>
*/
/**
- this function make the signature of some continuous records
- please refer the NFC forum specification "Signature Record type Definition"
+ this function make the signature of some continuous records
+ please refer the NFC forum specification "Signature Record type Definition"
- @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added.
- @param[in] begin_index the index of beginning record that will be signed.
- @param[in] end_index the last index of record that will be signed.
- @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type)
- @param[in] passowrd the password of cert_file
+ @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added.
+ @param[in] begin_index the index of beginning record that will be signed.
+ @param[in] end_index the last index of record that will be signed.
+ @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type)
+ @param[in] passowrd the password of cert_file
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @code
- ndef_message_h msg = NULL;
+ @code
+ ndef_message_h msg = NULL;
- // create a ndef message and add some records
- // ...
+ // create a ndef message and add some records
+ // ...
- net_nfc_sign_records(msg, 0, 1, "/tmp/cert.p12", "abcdef");
- @endcode
+ net_nfc_sign_records(msg, 0, 1, "/tmp/cert.p12", "abcdef");
+ @endcode
*/
net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password);
/**
- this function make the signature of whole records in NDEF message
+ this function make the signature of whole records in NDEF message
- @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added.
- @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type)
- @param[in] passowrd the password of cert_file
+ @param[in/out] msg NDEF message handler. After executing this function, a signature record will be added.
+ @param[in] cert_file PKCS #12 type certificate file (.p12). And the file should be encoded in DER type. (NOT PEM type)
+ @param[in] passowrd the password of cert_file
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @code
- ndef_message_h msg = NULL;
+ @code
+ ndef_message_h msg = NULL;
- // create a ndef message and add some records
- // ...
+ // create a ndef message and add some records
+ // ...
- net_nfc_sign_ndef_message(msg, "/tmp/cert.p12", "abcdef");
- @endcode
+ net_nfc_sign_ndef_message(msg, "/tmp/cert.p12", "abcdef");
+ @endcode
*/
net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password);
/**
- This function does verify signature of records
- record MUST be continuous.
+ This function does verify signature of records
+ record MUST be continuous.
- @param[in] begin_record the handle of beginning record that will be verified
- @param[in] sign_record the handle of signature record
+ @param[in] begin_record the handle of beginning record that will be verified
+ @param[in] sign_record the handle of signature record
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @code
- net_nfc_error_e error = NET_NFC_OK;
- ndef_message_h msg = NULL;
- ndef_record_h begin_record = NULL;
- ndef_record_h sign_record = NULL;
+ @code
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h begin_record = NULL;
+ ndef_record_h sign_record = NULL;
- // import NDEF message including the signature record.
- // ...
+ // import NDEF message including the signature record.
+ // ...
- net_nfc_get_record_by_index(msg, 0, &begin_record);
- net_nfc_get_record_by_index(msg, 2, &sign_record);
+ net_nfc_get_record_by_index(msg, 0, &begin_record);
+ net_nfc_get_record_by_index(msg, 2, &sign_record);
- error = net_nfc_verify_signature_records(begin_record, sign_record);
+ error = net_nfc_verify_signature_records(begin_record, sign_record);
- return (error == NET_NFC_OK);
- @endcode
+ return (error == NET_NFC_OK);
+ @endcode
*/
net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record);
/**
- This function does verify signature in NDEF message
- If message has 2 or more signature record, it should do verify every signatures and return result.
- (Despite of failing only one signature record, this function will return error.)
+ This function does verify signature in NDEF message
+ If message has 2 or more signature record, it should do verify every signatures and return result.
+ (Despite of failing only one signature record, this function will return error.)
- @param[in] msg NDEF message that will be verified.
+ @param[in] msg NDEF message that will be verified.
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @code
- net_nfc_error_e error = NET_NFC_OK;
- ndef_message_h msg = NULL;
+ @code
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
- // import NDEF message including the signature record.
- // ...
+ // import NDEF message including the signature record.
+ // ...
- error = net_nfc_verify_signature_ndef_message(msg);
+ error = net_nfc_verify_signature_ndef_message(msg);
- return (error == NET_NFC_OK);
- @endcode
+ return (error == NET_NFC_OK);
+ @endcode
*/
net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg);
#endif
-#endif /* __NET_NFC_SIGN_RECORD_H */
-
-
+#endif //__NET_NFC_SIGN_RECORD_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_TAG_H__
-#define __NET_NFC_TAG_H__
-
-#include "net_nfc_typedef.h"
-
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/**
-
-@addtogroup NET_NFC_MANAGER_TAG
-@{
- This document is for the APIs reference document
-
- NFC Manager defines are defined in <net_nfc_typedef.h>
-
- @li @c #net_nfc_transceive provide low level tag access
- @li @c #net_nfc_format_ndef format to NDEF tag type
- @li @c #net_nfc_read_tag read ndef message
- @li @c #net_nfc_write_ndef write ndef message
- @li @c #net_nfc_set_tag_filter set detection filter .
- @li @c #net_nfc_get_tag_filter get detection filter
- @li @c #net_nfc_create_transceive_info_only allocate the transceive info.
- @li @c #net_nfc_create_transceive_info allocate the transeeive info and set given values
- @li @c #net_nfc_set_transceive_info_command command setter from transceive info.
- @li @c #net_nfc_set_transceive_info_data data setter from transceive info.
- @li @c #net_nfc_set_transceive_info_address address setter from transceive info.
- @li @c #net_nfc_free_transceive_info free transceive info handler
-
-*/
-
-/**
- transceive function is the only wayt to access the raw format card (not formated),
- each tag type requres own command to access tags,
- this API provide low level access of tag operation and you require the knowlege of each tag technology. <BR>
- To use this API you should create transceive info with "net_nfc_create_transceive_info" API
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] handle target ID that has been delivered from callback
- @param[in] info trnasceive infomation that has created by "net_nfc_create_transceive_info" API
- @param[in] trans_param user data that will be delivered to callback
-
- @return return the result of the calling this function
-
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
-
- @code
-
- void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- net_nfc_get_tag_handle (target_info, &id);
-
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- net_nfc_transceive_info_h trans;
- net_nfc_create_transceive_info (&trans, NET_NFC_EMIFAREREAD, 0x00, NULL);
- net_nfc_transceive (id ,trans , &user_context);
- net_nfc_free_transceive_info (trans);
- }
- break;
-
- case NET_NFC_MESSAGE_TRANSCEIVE:
- if(result == NET_NFC_OK){
- printf("NET_NFC_MESSAGE_TRANSCEIVE is OK \n");
- if (data != NULL){
- data_h read_data = (data_h) * data;
- int idx;
- uint8_t * buf = net_nfc_get_data_buffer (data_read);
- for (idx = 0; idx < net_nfc_get_data_length (read_data); idx ++){
- printf (" %02X", buf[idx]);
- }
- }
- }
- else{
- printf("NET_NFC_MESSAGE_TRANSCEIVE is failed %d\n", result);
- }
- break;
- }
-
- int main()
- {
-
- net_nfc_error_e result;
- result = net_nfc_initialize();
- check_result(result);
-
- result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);
- check_result(result);
-
- sleep (100);
-
- return 0;
- }
- @endcode
-
-*/
-
-net_nfc_error_e net_nfc_transceive (net_nfc_target_handle_h handle, data_h rawdata, void* trans_param);
-
-/**
- This API formats the detected tag that can store NDEF message.
- some tags are required authentication. if the detected target does need authentication, set NULL.
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] handle target ID that has been delivered from callback
- @param[in] key key value that may need to format the tag
- @param[in] trans_param user data that will be delivered to callback
-
- @return return the result of the calling this function
-
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
- @exception NET_NFC_TAG_IS_ALREADY_FORMATTED requested target is already famatted
-
- @code
-
- void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
-
- if(data != NULL){
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- net_nfc_get_tag_handle (target_info, &id);
-
- if (!is_ndef){
- net_nfc_format_ndef (id, NULL, NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_FORMAT_NDEF:
- printf ("ndef format is completed with %d\n", result);
- break;
- }
- @endcode
-
-*/
-
-net_nfc_error_e net_nfc_format_ndef(net_nfc_target_handle_h handle, data_h key, void* trans_param);
-
-
-
-/**
- net_nfc_Ndef_read do read operation with NDEF format
- In the callback function, return value is byte array of the NDEF message.
- it need to convert to NDEF structure
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] handle the target ID the connection is already made
- @param[in] trans_param user data
-
- @return return the result of the calling this function
-
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_NO_NDEF_SUPPORT Tag is not support NDEF message
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
-
- @code
- void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- // ......
- switch (message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- if(data != NULL){
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- net_nfc_get_tag_handle (target_info, &id);
-
- if (is_ndef){
- net_nfc_read_tag (id, &user_context);
- }
- }
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF:
- {
- if (result != NET_NFC_OK)
- {
- // FAILED read NDEF message
- }
- ndef_message_h ndef_message = (ndef_message_h ) data;
- }
- break;
- }
- return;
- }
-
- int main()
- {
-
- net_nfc_error_e result;
- result = net_nfc_initialize();
- check_result(result);
-
- result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);
- check_result(result);
-
- sleep (100);
-
- return 0;
- }
- @endcode
-
-*/
-
-
-net_nfc_error_e net_nfc_read_tag (net_nfc_target_handle_h handle, void* trans_param);
-
-/**
- net_nfc_Ndef_write do write operation with NDEF format message
-
- \par Sync (or) Async: Async
- This is a Asynchronous API
-
- @param[in] handle the target Id the connection is already made
- @param[in] msg the message will be write to the target
- @param[in] trans_param user data
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_NO_NDEF_SUPPORT Tag is not support NDEF message
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_INSUFFICIENT_STORAGE Tag does not enough storage to store NDEF message
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
-
-
- @code
- void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- // ......
- switch (message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- if(data != NULL){
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- net_nfc_get_tag_handle (target_info, &id);
-
- if (is_ndef){
- net_nfc_error_e result = NET_NFC_OK;
- ndef_message_h bt_msg = NULL;
- ndef_record_h record = NULL;
-
- net_nfc_create_ndef_message (&msg);
- net_nfc_create_text_type_record (&record , "Hello NFC World", NET_NFC_LANG_EN_US ,NET_NFC_ENCODE_UTF_8);
- net_nfc_append_record_to_ndef_message (msg ,record);
-
- net_nfc_write_ndef(id, msg, &user_context);
- }
- }
- }
- break;
-
- case NET_NFC_MESSAGE_WRITE_NDEF:
- {
- if (result != NET_NFC_OK)
- {
- // FAILED write NDEF message
- }
- }
- break;
- }
- return;
- }
-
- int main()
- {
-
- net_nfc_error_e result;
- result = net_nfc_initialize();
- check_result(result);
-
- result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);
- check_result(result);
-
- sleep (100);
-
- return 0;
- }
- @endcode
-
-*/
-
-net_nfc_error_e net_nfc_write_ndef (net_nfc_target_handle_h handle, ndef_message_h msg, void* trans_param);
-
-/**
- this API make a ndef tag read only.
-
- \par Sync (or) Async: Async
- This is a synchronous API
-
- @param[in] handle the target Id the connection is already made
- @param[in] trans_param user data
-
- @return return the result of the calling the function
-
- @exception NONE
-
- @code
-
- @code
- void net_nfc_cb(net_nfc_message_e message, net_nfc_error_e result, void* data , void* userContext)
- {
- // ......
- switch (message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- if(data != NULL){
- net_nfc_target_handle_h id;
- bool is_ndef;
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- net_nfc_get_tag_ndef_support (target_info, &is_ndef);
- net_nfc_get_tag_handle (target_info, &id);
-
- if (is_ndef){
-
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_make_read_only_ndef_tag(id, &user_context);
- }
- }
- }
- break;
-
- case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF:
- {
- if (result != NET_NFC_OK)
- {
- // FAILED to make read only ndef tag
- }
- }
- break;
- }
- return;
- }
-
- int main()
- {
-
- net_nfc_error_e result;
- result = net_nfc_initialize();
- check_result(result);
-
- result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);
- check_result(result);
-
- sleep (100);
-
- return 0;
- }
- @endcode
-
-*/
-
-
-net_nfc_error_e net_nfc_make_read_only_ndef_tag(net_nfc_target_handle_h handle, void* trans_param);
-
-/**
- this API help to set filter of target types.
- bit opertor or can be used in the config parameter (like NET_NFC_ISO14443A_ENABLE | NET_NFC_ISO14443B_ENABLE)
- or you may choose "NET_NFC_ALL_ENABLE" enum value to get all result
- it prevent getting tag types from RF level.
- if the client api does call this function, default is always NET_NFC_ALL_ENABLE.
-
- \par Sync (or) Async: Sync
- This is a synchronous API
-
- @param[in] config filter value with bits operation
-
- @return return the result of the calling the function
-
- @exception NONE
-
- @code
-
- int main()
- {
-
- net_nfc_error_e result;
- result = net_nfc_initialize();
- check_result(result);
-
- net_nfc_event_filter_e filter = NET_NFC_ALL_ENABLE;
- net_nfc_error_e net_nfc_set_tag_filter(filter);
-
- result = net_nfc_set_response_callback (net_nfc_cb, &user_context2);
- check_result(result);
-
- sleep (100);
-
- return 0;
- }
-
- @endcode
-*/
-
-net_nfc_error_e net_nfc_set_tag_filter(net_nfc_event_filter_e config);
-
-/**
- get current filter status. The current filter value will return filter you can call this API any time anywhere
-
- \par Sync (or) Async: Async
- This is a asynchronous API
-
- @return return the filter which is set
-
- @exception NONE
-
- @code
-
- net_nfc_event_filter_e config = net_nfc_get_tag_filter();
-
- @endcode
-
-*/
-net_nfc_error_e net_nfc_is_tag_connected(void *trans_param);
-
-/**
- Check a target connected already. (Synchronous function)
-
- \par Sync (or) Async: Sync
- This is a synchronous API
-
- @param[out] dev_type currently connected device type
- @return return the filter which is set
-
- @exception NONE
-
- @code
-
- int dev_type = 0;
- net_nfc_error_e result = net_nfc_is_tag_connected_sync(&dev_type);
-
- @endcode
-*/
-net_nfc_error_e net_nfc_is_tag_connected_sync(int *dev_type);
-
-net_nfc_event_filter_e net_nfc_get_tag_filter(void);
-
-net_nfc_error_e net_nfc_get_current_tag_info(void* trans_param);
-net_nfc_error_e net_nfc_get_current_tag_info_sync(net_nfc_target_info_h *info);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_TAG_FELICA_H__
-#define __NET_NFC_TAG_FELICA_H__
-
-#include "net_nfc_typedef.h"
-
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/**
-
-@addtogroup NET_NFC_MANAGER_TAG
-@{
-
- send poll request to felica tag.
- Use this command to acquire and identify a card. Acqusition of IDm and PMm is possible with this command.
- By specifying a request code , you can acquire system code or communication performance of the system.
- By specifying a time slot, you can designate the maximum number of time slots possible to return response.
-
- NET_NFC_FELICA_POLL_NO_REQUEST = 0x00
- NET_NFC_FELICA_POLL_SYSTEM_CODE_REQUEST = 0x01
- NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST= 0x02
-
- time slot
-
- Time slot Max number of slots
- 0x00, 1
- 0x01, 2
- 0x03, 4
- 0x07, 8
- 0x0f, 16
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] req_code request code with this command
- @param[in] time_slot time slot value
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (SYSTEM_CODE, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_felica_poll (net_nfc_target_handle_h handle, net_nfc_felica_poll_request_code_e req_code, uint8_t time_slote, void* trans_param);
-
-/**
- Use this command to check for the existence of Area / Service specified by Area Code / Service Code
- If the specified Area / Service exists, the card returns version information of the key known as "Key Version" (2 Bytes)
- If the specified Area / Service does not exist, the card returns 0xffff as it s Key Version
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] number_of_area_service the number of specified Area / Service list
- @param[in] area_service_list specified Area / Service list
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value
-
-*/
-
-net_nfc_error_e net_nfc_felica_request_service (net_nfc_target_handle_h handle, uint8_t number_of_area_service, uint16_t area_service_list[], uint8_t number_of_services, void* trans_param);
-
-/**
- Use this command to check whether a card exist
- the Current mode of the card is returned.
-
- Mode
-
- 0x00 Mode0
- 0x01 Mode1
- 0x02 Mode2
- 0x03 Mode3
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct
-
-*/
-
-net_nfc_error_e net_nfc_felica_request_response (net_nfc_target_handle_h handle, void* trans_param);
-
-/**
- Use this command to read block data from a Service that requires no authentification
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] number_of_service the number of service list to read
- @param[in] service_list specified Service list to read
- @param[in] number_of_blocks the number of blocks to read
- @param[in] block_list the blocks to read
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct
-
-*/
-
-net_nfc_error_e net_nfc_felica_read_without_encryption (net_nfc_target_handle_h handle, uint8_t number_of_services, uint16_t service_list[], uint8_t number_of_blocks, uint8_t block_list[], void* trans_param);
-
-/**
- Use this command to write block data to a Service that requires no authentification
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] number_of_service the number of service list to write
- @param[in] service_list specified Service list to write
- @param[in] number_of_blocks the number of blocks to write
- @param[in] block_list the blocks to write
- @param[in] data the data to write
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct. number of services exceed max value, the data length to write is exceed the limitation. It should be less than number_of_blocks * 16 bytes
-
-*/
-
-net_nfc_error_e net_nfc_felica_write_without_encryption (net_nfc_target_handle_h handle, uint8_t number_of_services, uint16_t service_list[], uint8_t number_of_blocks, uint8_t block_list[], data_h data, void* trans_param);
-
-/**
- Use this command to acquire system code of the system located on a card
- If a card is divided into mutiple system, this command acquires system code of all the system existing in the card
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (IDm, etc) is not founded
- @exception NET_NFC_OUT_OF_BOUND the length of IDm is not correct.
-
-*/
-
-net_nfc_error_e net_nfc_felica_request_system_code (net_nfc_target_handle_h handle, void* trans_param);
-
-/**
-@} */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_TAG_JEWEL_H__
-#define __NET_NFC_TAG_JEWEL_H__
-
-#include "net_nfc_typedef.h"
-
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/**
-
-@addtogroup NET_NFC_MANAGER_TAG
-@{
-
- read uid from jewel tag.
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_jewel_read_id (net_nfc_target_handle_h handle, void* trans_param);
-
-/**
- read one byte of specific address .
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] block block number. (block 0 ~ block E)
- @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_jewel_read_byte (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, void* trans_param);
-
-/**
- read all byte from tag .
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-
-net_nfc_error_e net_nfc_jewel_read_all (net_nfc_target_handle_h handle, void* trans_param);
-
-
-/**
- operate erase and write cycle . If any of BLOCK-0 to BLOCK-D is locked then write with erase is barred form thoes blocks.
- Additionally 0, D, E blocks are automatically in the lock condition. so write with erase is always barred from thoes blocks.
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] block block number. (block 0 ~ block E)
- @param[in] data the data to write
- @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_jewel_write_with_erase (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, uint8_t data, void* trans_param);
-
-
-/**
- operate no erase and write cycle .
-
- The WRITE-NE command is available for three main purposes
- - Lock . to set the ��lock bit�� for a block
- - OTP . to set One-Time-Programmable bits (bytes 2 . 7 of Block-E), where between one and eight OTP bits can be set with a singleWRITE-NE command
- - A fast-write in order to reduce overall time to write data to memory blocks for the first time given that the original condition of memory is zero
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] block block number. (block 0 ~ block E)
- @param[in] data the data to write
- @param[in] byte byte number. Each block has 8 bytes. (byte 0 ~ byte 7)
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
-
-*/
-
-net_nfc_error_e net_nfc_jewel_write_with_no_erase (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, uint8_t data, void* trans_param);
-
-/**
-@} */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
-
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#ifndef __NET_NFC_TAG_MIFARE_H__
#define __NET_NFC_TAG_MIFARE_H__
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
/**
-@addtogroup NET_NFC_MANAGER_TAG
-@{
- Authenticate a sector with key A. I/O operation. e.g. read / write / increment / decrement will be available after successful authentication.
- This API is only available for MIFARE classic
+ @addtogroup NET_NFC_MANAGER_TAG
+ @{
+ Authenticate a sector with key A. I/O operation. e.g. read / write /
+ increment / decrement will be available after successful authentication.
+ This API is only available for MIFARE classic
- MIFARE CLASSIC MINI
- => 0 ~ 4 : 5 sector and 4 block with 16 bytes
+ MIFARE CLASSIC MINI
+ => 0 ~ 4 : 5 sector and 4 block with 16 bytes
- MIFARE CLASSIC 1K
- => 0 ~ 15 : 16 sector and 4 block with 16 bytes
+ MIFARE CLASSIC 1K
+ => 0 ~ 15 : 16 sector and 4 block with 16 bytes
- MIFARE CLASSIC 4K
- => 0 ~ 31 : 32 sector and 4 block with 16 bytes
- => 32 ~ 39 : 8 sector and 16 block with 16 bytes
+ MIFARE CLASSIC 4K
+ => 0 ~ 31 : 32 sector and 4 block with 16 bytes
+ => 32 ~ 39 : 8 sector and 16 block with 16 bytes
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] handle target handle of detected tag
- @param[in] sector sector to authenticate with key A
- @param[in] auth_key 6 byte key to authenticate the sector
+ @param[in] handle target handle of detected tag
+ @param[in] sector sector to authenticate with key A
+ @param[in] auth_key 6 byte key to authenticate the sector
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
*/
-net_nfc_error_e net_nfc_mifare_authenticate_with_keyA(net_nfc_target_handle_h handle, uint8_t sector, data_h auth_key, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyA(
+ net_nfc_target_handle_h handle,
+ uint8_t sector,
+ data_h auth_key,
+ void *callback,
+ void *user_data);
/**
- Authenticate a sector with key B. I/O operation. e.g. read / write / increment / decrement will be available after successful authentication.
- This API is only available for MIFARE classic
+ Authenticate a sector with key B. I/O operation. e.g. read / write /
+ increment / decrement will be available after successful authentication.
+ This API is only available for MIFARE classic
- MIFARE CLASSIC MINI
- => 0 ~ 4 : 5 sector and 4 block with 16 bytes
+ MIFARE CLASSIC MINI
+ => 0 ~ 4 : 5 sector and 4 block with 16 bytes
- MIFARE CLASSIC 1K
- => 0 ~ 15 : 16 sector and 4 block with 16 bytes
+ MIFARE CLASSIC 1K
+ => 0 ~ 15 : 16 sector and 4 block with 16 bytes
- MIFARE CLASSIC 4K
- => 0 ~ 31 : 32 sector and 4 block with 16 bytes
- => 32 ~ 39 : 8 sector and 16 block with 16 bytes
+ MIFARE CLASSIC 4K
+ => 0 ~ 31 : 32 sector and 4 block with 16 bytes
+ => 32 ~ 39 : 8 sector and 16 block with 16 bytes
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] handle target handle of detected tag
- @param[in] sector sector to authenticate with key B
- @param[in] auth_key 6 byte key to authenticate the sector
+ @param[in] handle target handle of detected tag
+ @param[in] sector sector to authenticate with key B
+ @param[in] auth_key 6 byte key to authenticate the sector
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_NO_DATA_FOUND mendantory tag info (UID, etc) is not founded
*/
-net_nfc_error_e net_nfc_mifare_authenticate_with_keyB(net_nfc_target_handle_h handle, uint8_t sector, data_h auth_key, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB(
+ net_nfc_target_handle_h handle,
+ uint8_t sector,
+ data_h auth_key,
+ void *callback,
+ void *user_data);
/**
- read block or read page. If detected card is MIFARE classic, then It will read a block (16 byte). If detected card is Ultra light, then It will read 4 page (16 block)
-
- \par Sync (or) Async: Sync
- This is a Asynchronous API
-
- @param[in] handle target handle of detected tag
- @param[in] addr block or starting page number
-
- @return return the result of the calling the function
-
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
-
+ read block or read page. If detected card is MIFARE classic, then It will
+ read a block (16 byte). If detected card is Ultra light, then It will read
+ 4 page (16 block)
+
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
+
+ @param[in] handle target handle of detected tag
+ @param[in] addr block or starting page number
+
+ @return return the result of the calling the function
+
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_READ_FAILED received chunked data is not valied (damaged data is recieved) or error ack is recieved
*/
-net_nfc_error_e net_nfc_mifare_read(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_read(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data);
/**
- write block (16 byte) to addr. Only 4 bytes will be written when tag is ultra light
+ write block (16 byte) to addr. Only 4 bytes will be written when tag is
+ ultra light
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] handle target handle of detected tag
- @param[in] addr block or starting page number
- @param[in] data data to write
+ @param[in] handle target handle of detected tag
+ @param[in] addr block or starting page number
+ @param[in] data data to write
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
*/
-net_nfc_error_e net_nfc_mifare_write_block (net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_write_block(
+ net_nfc_target_handle_h handle,
+ uint8_t addr,
+ data_h data,
+ void *callback,
+ void *user_data);
/**
- write page (4 byte) to addr. Only 4 bytes will be written when tag is MIFARE classic
+ write page (4 byte) to addr. Only 4 bytes will be written when tag is
+ MIFARE classic
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] handle target handle of detected tag
- @param[in] addr block or starting page number
- @param[in] data data to write
+ @param[in] handle target handle of detected tag
+ @param[in] addr block or starting page number
+ @param[in] data data to write
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
*/
-net_nfc_error_e net_nfc_mifare_write_page (net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_write_page(
+ net_nfc_target_handle_h handle,
+ uint8_t addr,
+ data_h data,
+ void *callback,
+ void *user_data);
/**
- Increase a value block, storing the result in the temporary block on the tag.
- This API is only available for MIFARE classic
+ Increase a value block, storing the result in the temporary block on the
+ tag
+ This API is only available for MIFARE classic
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] handle target handle of detected tag
- @param[in] addr block
- @param[in] value index of block to increase, starting from 0
+ @param[in] handle target handle of detected tag
+ @param[in] addr block
+ @param[in] value index of block to increase, starting from 0
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
*/
-net_nfc_error_e net_nfc_mifare_increment(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_increment(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ int value,
+ void *callback,
+ void *user_data);
/**
- Decrease a value block, storing the result in the temporary block on the tag.
- This API is only available for MIFARE classic
+ Decrease a value block, storing the result in the temporary block on the tag
+ This API is only available for MIFARE classic
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] handle target handle of detected tag
- @param[in] addr block
- @param[in] value index of block to decrease, starting from 0
+ @param[in] handle target handle of detected tag
+ @param[in] addr block
+ @param[in] value index of block to decrease, starting from 0
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
*/
-net_nfc_error_e net_nfc_mifare_decrement(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_decrement(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ int value,
+ void *callback,
+ void *user_data);
/**
- Copy from the temporary block to a value block.
- This API is only available for MIFARE classic
+ Copy from the temporary block to a value block.
+ This API is only available for MIFARE classic
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] handle target handle of detected tag
- @param[in] addr block
- @param[in] value index of block to decrease, starting from 0
+ @param[in] handle target handle of detected tag
+ @param[in] addr block
+ @param[in] value index of block to decrease, starting from 0
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
*/
-net_nfc_error_e net_nfc_mifare_transfer(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data);
/**
- Copy from a value block to the temporary block.
- This API is only available for MIFARE classic
+ Copy from a value block to the temporary block.
+ This API is only available for MIFARE classic
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] handle target handle of detected tag
- @param[in] addr block
- @param[in] value index of block to decrease, starting from 0
+ @param[in] handle target handle of detected tag
+ @param[in] addr block
+ @param[in] value index of block to decrease, starting from 0
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
- @exception NET_NFC_BUSY Device is too busy to handle your request
- @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
- @exception NET_NFC_RF_TIMEOUT Timeout is raised while communicate with tag
- @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
- @exception NET_NFC_INVALID_HANDLE target handle is not valid
- @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
+ @exception NET_NFC_NULL_PARAMETER parameter has illigal NULL pointer
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NOT_INITIALIZED Try to operate without initialization
+ @exception NET_NFC_BUSY Device is too busy to handle your request
+ @exception NET_NFC_OPERATION_FAIL Operation is failed because of the internal oal error
+ @exception NET_NFC_RF_TIMEOUT Timeout raised while communicate with tag
+ @exception NET_NFC_NOT_SUPPORTED you may recieve this error if you request not supported command
+ @exception NET_NFC_INVALID_HANDLE target handle is not valid
+ @exception NET_NFC_TAG_WRITE_FAILED read only tag, or error ack is received from tag
*/
-net_nfc_error_e net_nfc_mifare_restore(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param);
+net_nfc_error_e net_nfc_client_mifare_restore(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data);
/**
- create default factory key. The key is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ create default factory key. The key is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] key the handle to create key
+ @param[in] key the handle to create key
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
*/
-net_nfc_error_e net_nfc_mifare_create_default_key(data_h* key);
+net_nfc_error_e net_nfc_client_mifare_create_default_key(data_h* key);
/**
- create mifare application directory key. The key is 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5
+ create mifare application directory key. The key is 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] key the handle to create key
+ @param[in] key the handle to create key
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
*/
-net_nfc_error_e net_nfc_mifare_create_application_directory_key(data_h* key);
+net_nfc_error_e net_nfc_client_mifare_create_application_directory_key(
+ data_h* key);
/**
- create nfc forum key. The key is 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7
+ create nfc forum key. The key is 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7
- \par Sync (or) Async: Sync
- This is a Asynchronous API
+ \par Sync (or) Async: Sync
+ This is a Asynchronous API
- @param[in] key the handle to create key
+ @param[in] key the handle to create key
- @return return the result of the calling the function
+ @return return the result of the calling the function
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
*/
-net_nfc_error_e net_nfc_mifare_create_net_nfc_forum_key(data_h* key);
+net_nfc_error_e net_nfc_client_mifare_create_net_nfc_forum_key(data_h* key);
/**
-@} */
-
+@}
+*/
#ifdef __cplusplus
}
#endif
-
-#endif
-
+#endif //__NET_NFC_TAG_MIFARE_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#ifndef __NET_NFC_TARGET_INFO_H__
#define __NET_NFC_TARGET_INFO_H__
/**
-@addtogroup NET_NFC_MANAGER_INFO
-@{
- This document is for the APIs reference document
+ @addtogroup NET_NFC_MANAGER_INFO
+ @{
+ This document is for the APIs reference document
- NFC Manager defines are defined in <nfc-typedef.h>
+ NFC Manager defines are defined in <nfc-typedef.h>
- These APIs help to get infomation of detected target. these target info handler holds
- - type of target
- - target ID
- - ndef message supporting
- - max data size (if this tag is ndef message tag)
- - actual data size (if this tag is ndef message tag)
-*/
+ These APIs help to get infomation of detected target. these target info handler holds
+ - type of target
+ - target ID
+ - ndef message supporting
+ - max data size (if this tag is ndef message tag)
+ - actual data size (if this tag is ndef message tag)
+ */
/**
- type getter from targte info handler
+ type getter from targte info handler
- \par Sync (or) Async: Sync
- This is a Synchronous API
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
- @param[in] target_info target info handler
- @param[out] type tag type these type is one of the enum "net_nfc_target_type_e" defined
+ @param[in] target_info target info handler
+ @param[out] type tag type these type is one of the enum "net_nfc_target_type_e" defined
- @return return the result of calling this functions
+ @return return the result of calling this functions
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_get_tag_type (net_nfc_target_info_h target_info, net_nfc_target_type_e * type);
/**
- type getter from targte info handler
+ type getter from targte info handler
- \par Sync (or) Async: Sync
- This is a Synchronous API
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
- @param[in] target_info target info handler
- @param[out] handle target handle that is generated by nfc-manager
+ @param[in] target_info target info handler
+ @param[out] handle target handle that is generated by nfc-manager
- @return return the result of calling this functions
+ @return return the result of calling this functions
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle);
/**
- this API returns the NDEF support boolean value.
- The TRUE value will be returned if the detected target is support NDEF, or return FALSE
+ this API returns the NDEF support boolean value.
+ The TRUE value will be returned if the detected target is support NDEF, or return FALSE
- \par Sync (or) Async: Sync
- This is a Synchronous API
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
- @param[in] target_info target info handler
- @param[out] is_support boolean value of NDEF supporting
+ @param[in] target_info target info handler
+ @param[out] is_support boolean value of NDEF supporting
- @return return the result of calling this functions
+ @return return the result of calling this functions
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_get_tag_ndef_support (net_nfc_target_info_h target_info, bool * is_support);
/**
- The max size getter from targte info handler. This max size indicates the maximum size of NDEF message that can be stored in this detected tag.
+ The max size getter from targte info handler. This max size indicates the maximum size of NDEF message that can be stored in this detected tag.
- \par Sync (or) Async: Sync
- This is a Synchronous API
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
- @param[in] target_info target info handler
- @param[out] max_size max size of NDEF message that can be stored in this detected tag.
+ @param[in] target_info target info handler
+ @param[out] max_size max size of NDEF message that can be stored in this detected tag.
- @return return the result of calling this functions
+ @return return the result of calling this functions
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
net_nfc_error_e net_nfc_get_tag_max_data_size (net_nfc_target_info_h target_info, uint32_t * max_size);
/**
- this function return the actual NDEF message size that stored in the tag
+ this function return the actual NDEF message size that stored in the tag
- \par Sync (or) Async: Sync
- This is a Synchronous API
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
- @param[in] target_info target info handler
- @param[out] actual_data the actual NDEF message size that stored in the tag
+ @param[in] target_info target info handler
+ @param[out] actual_data the actual NDEF message size that stored in the tag
- @return return the result of calling this functions
+ @return return the result of calling this functions
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
*/
/**
- this function return keys which will be used to get a tag information
-
- \par Sync (or) Async: Sync
- This is a Synchronous API. keys will be freed by user.
-
- @param[in] target_info target info handler
- @param[out] keys pointer of double array. it will be array of string.
- @param[out] number_of_keys length of array.
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
- @exception NET_NFC_ALLOC_FAIL memory allocation is failed
- @exception NET_NFC_NO_DATA_FOUND No data is returned
-
- @code
- void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)
- {
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- if(info != NULL)
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- char **keys;
- int keys_length;
-
- if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == true)
- {
- int index = 0;
- for(; index < keys_length; index++)
- {
- char* key = keys[index];
- }
- }
-
- free(keys);
- }
- }
- }
-
- }
- @endcode
-
- @return return the result of calling this functions
+ this function return keys which will be used to get a tag information
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API. keys will be freed by user.
+
+ @param[in] target_info target info handler
+ @param[out] keys pointer of double array. it will be array of string.
+ @param[out] number_of_keys length of array.
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illigal NULL pointer(s)
+ @exception NET_NFC_ALLOC_FAIL memory allocation is failed
+ @exception NET_NFC_NO_DATA_FOUND No data is returned
+
+ @code
+ void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)
+ {
+
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+ if(info != NULL)
+ {
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ char **keys;
+ int keys_length;
+
+ if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == true)
+ {
+ int index = 0;
+ for(; index < keys_length; index++)
+ {
+ char* key = keys[index];
+ }
+ }
+
+ free(keys);
+ }
+ }
+ }
+ }
+ @endcode
+
+ @return return the result of calling this functions
*/
net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char ***keys, int* number_of_keys);
/**
- this function return value which is matched key
-
- \par Sync (or) Async: Sync
- This is a Synchronous API
-
- @param[in] target_info target info handler
- @param[in] key key to retrieve
- @param[out] value value which is matched with key
-
- @code
- void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)
- {
-
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- if(info != NULL)
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
-
- char** keys;
- int keys_length;
-
- if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == NET_NFC_OK)
- {
- int index = 0;
- for(; index < keys_length; index++)
- {
- char* key = keys[index];
- data_h value;
- net_nfc_get_tag_info_value(target_info, key, &value);
- net_nfc_free_data(value);
- }
- }
- }
- }
- }
-
- }
- @endcode
-
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
- @exception NET_NFC_NO_DATA_FOUND No data is returned
-*/
+ this function return value which is matched key
+
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
+
+ @param[in] target_info target info handler
+ @param[in] key key to retrieve
+ @param[out] value value which is matched with key
+
+ @code
+ void user_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* trans_param)
+ {
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+ if(info != NULL)
+ {
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+
+ char** keys;
+ int keys_length;
+
+ if(net_nfc_get_tag_info_keys(target_info, &keys, &keys_length) == NET_NFC_OK)
+ {
+ int index = 0;
+ for(; index < keys_length; index++)
+ {
+ char* key = keys[index];
+ data_h value;
+ net_nfc_get_tag_info_value(target_info, key, &value);
+ net_nfc_free_data(value);
+ }
+ }
+ }
+ }
+ }
+ }
+ @endcode
+
+ @return return the result of calling this functions
+
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_NO_DATA_FOUND No data is returned
+ */
net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value);
/**
- Duplicate a handle of target information
-
- ** IMPORTANT : After using duplicated handle, you should release a handle returned from this function.
- ** You can release a handle by net_nfc_release_tag_info function.
+ Duplicate a handle of target information
- \par Sync (or) Async: Sync
- This is a Synchronous API
+ ** IMPORTANT : After using duplicated handle, you should release a handle returned from this function.
+ ** You can release a handle by net_nfc_release_tag_info function.
- @param[in] origin The original handle you want to duplicate
- @param[out] result The result of this function.
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
- @code
- void user_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *trans_param)
- {
- switch(message)
- {
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_target_info_h handle = NULL;
+ @param[in] origin The original handle you want to duplicate
+ @param[out] result The result of this function.
- net_nfc_duplicate_target_info(target_info, &handle);
+ @code
+ void user_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *trans_param)
+ {
+ switch(message)
+ {
+ case NET_NFC_MESSAGE_TAG_DISCOVERED:
+ {
+ net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
+ net_nfc_target_info_h handle = NULL;
- // do something...
+ net_nfc_duplicate_target_info(target_info, &handle);
- net_nfc_release_tag_info(handle);
- }
- break;
- }
+ // do something...
- }
- @endcode
+ net_nfc_release_tag_info(handle);
+ }
+ break;
+ }
+ }
+ @endcode
- @return return the result of calling this functions
-
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @return return the result of calling this functions
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
*/
net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, net_nfc_target_info_h *result);
/**
- After using net_nfc_target_info_h handle, you should release its resource by this function.
+ After using net_nfc_target_info_h handle, you should release its resource by this function.
- ** IMPORTANT : Never use this function in user callback you registered by net_nfc_set_response_callback function
- ** This function is for the result of net_nfc_duplicate_target_info or net_nfc_get_current_tag_info_sync
+ ** IMPORTANT : Never use this function in user callback you registered by net_nfc_set_response_callback function
+ ** This function is for the result of net_nfc_duplicate_target_info or net_nfc_get_current_tag_info_sync
- \par Sync (or) Async: Sync
- This is a Synchronous API
+ \par Sync (or) Async: Sync
+ This is a Synchronous API
- @param[in] target_info target info handle
+ @param[in] target_info target info handle
- @code
- net_nfc_target_info_h handle;
+ @code
+ net_nfc_target_info_h handle;
- net_nfc_get_current_tag_info_sync(&handle);
+ net_nfc_get_current_tag_info_sync(&handle);
- // do something...
+ // do something...
- net_nfc_release_tag_info(handle);
- @endcode
+ net_nfc_release_tag_info(handle);
+ @endcode
- @return return the result of calling this functions
+ @return return the result of calling this functions
- @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
+ @exception NET_NFC_NULL_PARAMETER parameter(s) has(have) illegal NULL pointer(s)
*/
net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info);
/**
-@} */
+@}
+*/
#ifdef __cplusplus
#endif
-#endif
-
-
+#endif //__NET_NFC_TARGET_INFO_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#ifdef SECURITY_SERVER
+#include "security-server.h"
+#endif
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_client_se.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_tag.h"
+#include "net_nfc_client_ndef.h"
+#include "net_nfc_client_transceive.h"
+#include "net_nfc_client_llcp.h"
+#include "net_nfc_client_snep.h"
+#include "net_nfc_client_p2p.h"
+#include "net_nfc_client_test.h"
+#include "net_nfc_client_system_handler.h"
+#include "net_nfc_client_handover.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+#ifdef SECURITY_SERVER
+static uint8_t *cookie;
+static size_t cookie_len;
+
+static void _init_smack()
+{
+ if (cookie == NULL) {
+ cookie_len = security_server_get_cookie_size();
+ if (cookie_len > 0) {
+ cookie = g_new0(uint8_t, cookie_len);
+ if (cookie != NULL) {
+ if (security_server_request_cookie(
+ (char *)cookie,
+ cookie_len) < 0) {
+ g_free(cookie);
+ cookie = NULL;
+ }
+ }
+ }
+ }
+}
+
+static void _deinit_smack()
+{
+ if (cookie != NULL) {
+ g_free(cookie);
+ cookie = NULL;
+ }
+}
+#endif
+
+GVariant *net_nfc_client_gdbus_get_privilege()
+{
+#ifdef SECURITY_SERVER
+ return net_nfc_util_gdbus_buffer_to_variant(cookie, cookie_len);
+#else
+ return net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+#endif
+}
+
+void net_nfc_client_gdbus_init(void)
+{
+#ifdef SECURITY_SERVER
+ _init_smack();
+#endif
+ if (net_nfc_client_manager_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_tag_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_ndef_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_transceive_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_llcp_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_snep_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_p2p_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_sys_handler_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_se_init() != NET_NFC_OK)
+ return;
+ if (net_nfc_client_test_init() != NET_NFC_OK)
+ return;
+ if(net_nfc_client_handover_init() != NET_NFC_OK)
+ return;
+}
+
+void net_nfc_client_gdbus_deinit(void)
+{
+ net_nfc_client_handover_deinit();
+ net_nfc_client_test_deinit();
+ net_nfc_client_se_deinit();
+ net_nfc_client_sys_handler_deinit();
+ net_nfc_client_p2p_deinit();
+ net_nfc_client_snep_deinit();
+ net_nfc_client_llcp_deinit();
+ net_nfc_client_transceive_deinit();
+ net_nfc_client_ndef_deinit();
+ net_nfc_client_tag_deinit();
+ net_nfc_client_manager_deinit();
+#ifdef SECURITY_SERVER
+ _deinit_smack();
+#endif
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <vconf.h>
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_client.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_initialize()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_client_gdbus_init();
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_deinitialize()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_client_gdbus_deinit();
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_is_nfc_supported(int *state)
+{
+ net_nfc_error_e ret;
+
+ if (state != NULL)
+ {
+ if (vconf_get_bool(VCONFKEY_NFC_FEATURE, state) == 0)
+ {
+ ret = NET_NFC_OK;
+ }
+ else
+ {
+ ret = NET_NFC_INVALID_STATE;
+ }
+ }
+ else
+ {
+ ret = NET_NFC_NULL_PARAMETER;
+ }
+
+ return ret;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_get_nfc_state(int *state)
+{
+ net_nfc_error_e ret;
+
+ if (state != NULL)
+ {
+ if (vconf_get_bool(VCONFKEY_NFC_STATE, state) == 0)
+ {
+ ret = NET_NFC_OK;
+ }
+ else
+ {
+ ret = NET_NFC_INVALID_STATE;
+ }
+ }
+ else
+ {
+ ret = NET_NFC_NULL_PARAMETER;
+ }
+
+ return ret;
+}
#include <string.h>
#include "net_nfc_data.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_util_internal.h"
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data(data_h* data, const uint8_t* bytes, const uint32_t length)
{
- data_s *data_private = NULL;
+ data_s *tmp_data = NULL;
if (data == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- _net_nfc_util_alloc_mem(data_private, sizeof(data_s));
- if (data_private == NULL)
+ _net_nfc_util_alloc_mem(tmp_data, sizeof(data_s));
+ if (tmp_data == NULL)
return NET_NFC_ALLOC_FAIL;
if (length > 0)
{
- _net_nfc_util_alloc_mem(data_private->buffer, length);
- if (data_private->buffer == NULL)
+ _net_nfc_util_alloc_mem(tmp_data->buffer, length);
+ if (tmp_data->buffer == NULL)
{
- _net_nfc_util_free_mem(data_private);
+ _net_nfc_util_free_mem(tmp_data);
return NET_NFC_ALLOC_FAIL;
}
- data_private->length = length;
+ tmp_data->length = length;
if (bytes != NULL)
{
- memcpy(data_private->buffer, bytes, length);
+ memcpy(tmp_data->buffer, bytes, length);
}
}
- *data = (data_h)data_private;
+ *data = (data_h)tmp_data;
return NET_NFC_OK;
}
{
return NET_NFC_NULL_PARAMETER;
}
- data_s * data_private = (data_s *)data;
+ data_s * tmp_data = (data_s *)data;
- *bytes = data_private->buffer;
- *length = data_private->length;
+ *bytes = tmp_data->buffer;
+ *length = tmp_data->length;
return NET_NFC_OK;
}
{
return NET_NFC_NULL_PARAMETER;
}
- data_s * data_private = (data_s *)data;
+ data_s * tmp_data = (data_s *)data;
- if (data_private->buffer == bytes && data_private->length == length)
+ if (tmp_data->buffer == bytes && tmp_data->length == length)
{
return NET_NFC_OK;
}
- if (data_private->buffer != NULL)
+ if (tmp_data->buffer != NULL)
{
- _net_nfc_util_free_mem(data_private->buffer);
+ _net_nfc_util_free_mem(tmp_data->buffer);
}
if (length <= 0)
{
- data_private->buffer = NULL;
- data_private->length = 0;
+ tmp_data->buffer = NULL;
+ tmp_data->length = 0;
return NET_NFC_OK;
}
if (length > 0)
{
- _net_nfc_util_alloc_mem((data_private)->buffer, length);
+ _net_nfc_util_alloc_mem((tmp_data)->buffer, length);
}
if (bytes != NULL)
{
- memcpy(data_private->buffer, bytes, length);
+ memcpy(tmp_data->buffer, bytes, length);
}
- data_private->length = length;
+ tmp_data->length = length;
return NET_NFC_OK;
}
{
return 0;
}
- data_s * data_private = (data_s *)data;
+ data_s * tmp_data = (data_s *)data;
- return data_private->length;
+ return tmp_data->length;
}
NET_NFC_EXPORT_API uint8_t * net_nfc_get_data_buffer(const data_h data)
{
return NULL;
}
- data_s * data_private = (data_s *)data;
+ data_s * tmp_data = (data_s *)data;
- return data_private->buffer;
+ return tmp_data->buffer;
}
NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_data(data_h data)
{
return NET_NFC_NULL_PARAMETER;
}
- data_s * data_private = (data_s *)data;
+ data_s * tmp_data = (data_s *)data;
- if (data_private->buffer != NULL)
+ if (tmp_data->buffer != NULL)
{
- _net_nfc_util_free_mem(data_private->buffer);
+ _net_nfc_util_free_mem(tmp_data->buffer);
}
- _net_nfc_util_free_mem(data_private);
+ _net_nfc_util_free_mem(tmp_data);
return NET_NFC_OK;
}
-
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <glib.h>
-
-#ifdef USE_ECORE_MAIN_LOOP
-#include "Ecore.h"
-#endif
-
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_data.h"
-#include "net_nfc_exchanger_private.h"
-#include "net_nfc_tag.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_client_dispatcher_private.h"
-#include "net_nfc_client_nfc_private.h"
-
-
-extern unsigned int socket_handle;
-
-net_nfc_llcp_internal_socket_s *_find_internal_socket_info(net_nfc_llcp_socket_t socket);
-net_nfc_llcp_internal_socket_s *_find_internal_socket_info_by_oal_socket(net_nfc_llcp_socket_t socket);
-void _append_internal_socket(net_nfc_llcp_internal_socket_s *data);
-void _remove_internal_socket(net_nfc_llcp_internal_socket_s *data);
-void _net_nfc_llcp_close_all_socket();
-void _net_nfc_set_llcp_remote_configure(net_nfc_llcp_config_info_s *remote_data);
-
-typedef struct _client_dispatcher_param_t
-{
- net_nfc_response_cb client_cb;
- net_nfc_response_msg_t *msg;
-} client_dispatcher_param_t;
-
-/* static function */
-
-static net_nfc_error_e net_nfc_get_tag_info_list(data_s *values, int number_of_keys, net_nfc_tag_info_s **list);
-static bool net_nfc_client_dispatch_response(client_dispatcher_param_t *param);
-
-/////////////////////
-
-void _net_nfc_set_llcp_current_target_id(net_nfc_target_handle_s *handle);
-
-#ifdef SAVE_TARGET_INFO_IN_CC
-static void __net_nfc_clear_tag_info_cache (client_context_t *context)
-{
- if (context->target_info != NULL)
- {
- net_nfc_target_info_s *info = context->target_info;
- net_nfc_tag_info_s *list = info->tag_info_list;
-
- if (list != NULL)
- {
-
- int i = 0;
- net_nfc_tag_info_s *temp = list;
-
- while (i < info->number_of_keys)
- {
- if (list->key != NULL)
- free(list->key);
-
- if (list->value != NULL)
- net_nfc_free_data(list->value);
-
- list++;
- i++;
- }
-
- /* destroy list */
- free(temp);
- }
-
- if (info->keylist != NULL)
- {
- _net_nfc_util_free_mem(info->keylist);
- }
-
- _net_nfc_util_free_mem(context->target_info);
- context->target_info = NULL;
- }
-}
-#endif
-
-#ifdef USE_GLIB_MAIN_LOOP
-void net_nfc_client_call_dispatcher_in_g_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg)
-{
- client_dispatcher_param_t *param = NULL;
-
- DEBUG_CLIENT_MSG("put message to g main loop");
-
- _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t));
- if (param != NULL)
- {
- param->client_cb = client_cb;
- param->msg = msg;
-
- if (g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)net_nfc_client_dispatch_response, param, NULL))
- {
- g_main_context_wakeup(g_main_context_default());
- }
- }
-}
-#elif USE_ECORE_MAIN_LOOP
-void net_nfc_client_call_dispatcher_in_ecore_main_loop(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg)
-{
- client_dispatcher_param_t *param = NULL;
-
- DEBUG_CLIENT_MSG("put message to ecore main loop");
-
- _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t));
- if (param != NULL)
- {
- param->client_cb = client_cb;
- param->msg = msg;
-
- if (ecore_idler_add((Ecore_Task_Cb)net_nfc_client_dispatch_response, param) != NULL)
- {
- g_main_context_wakeup(g_main_context_default());
- }
- }
-}
-#else
-void net_nfc_client_call_dispatcher_in_current_context(net_nfc_response_cb client_cb, net_nfc_response_msg_t *msg)
-{
- client_dispatcher_param_t *param = NULL;
-
- DEBUG_CLIENT_MSG("invoke callback in current thread");
-
- _net_nfc_util_alloc_mem(param, sizeof(client_dispatcher_param_t));
- if (param != NULL)
- {
- param->client_cb = client_cb;
- param->msg = msg;
-
- net_nfc_client_dispatch_response(param);
- }
-}
-#endif
-
-static bool net_nfc_client_dispatch_response(client_dispatcher_param_t *param)
-{
- if (param == NULL)
- return false;
-
- net_nfc_response_cb client_cb = param->client_cb;
- net_nfc_response_msg_t *msg = param->msg;
-
- _net_nfc_util_free_mem(param);
-
- DEBUG_CLIENT_MSG("we have got message from nfc-daemon type = [%d]", msg->response_type);
-
- client_context_t *client_context = net_nfc_get_client_context();
-
- switch (msg->response_type)
- {
- case NET_NFC_MESSAGE_GET_SE :
- {
- if (client_cb != NULL)
- {
- client_cb(msg->response_type, ((net_nfc_response_get_se_t *)msg->detail_message)->result, &(((net_nfc_response_get_se_t *)msg->detail_message)->se_type), client_context->register_user_param, ((net_nfc_response_get_se_t *)msg->detail_message)->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_SET_SE :
- {
- if (client_cb != NULL)
- {
- client_cb(msg->response_type, ((net_nfc_response_set_se_t *)msg->detail_message)->result, &(((net_nfc_response_get_se_t *)msg->detail_message)->se_type), client_context->register_user_param, ((net_nfc_response_set_se_t *)msg->detail_message)->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_SE_TYPE_CHANGED :
- {
- if (client_cb != NULL)
- {
- client_cb(msg->response_type, NET_NFC_OK, NULL, NULL, NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
- {
- DEBUG_CLIENT_MSG("handle = [0x%p]", ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->handle);
-
- if (client_cb != NULL)
- {
- client_cb(msg->response_type, ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->result, (void *)((net_nfc_response_open_internal_se_t *)(msg->detail_message))->handle, client_context->register_user_param, ((net_nfc_response_open_internal_se_t *)(msg->detail_message))->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_close_internal_se_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_close_internal_se_t *)msg->detail_message)->trans_param);
- }
- break;
-
- case NET_NFC_MESSAGE_SEND_APDU_SE :
- {
- data_s *apdu = &(((net_nfc_response_send_apdu_t *)msg->detail_message)->data);
-
- if (apdu->length > 0)
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, apdu, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param);
- }
- else
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_GET_ATR_SE :
- {
- data_s *atr = &(((net_nfc_response_get_atr_t *)msg->detail_message)->data);
-
- if (atr->length > 0)
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_get_atr_t *)msg->detail_message)->result, atr, client_context->register_user_param, (void *)((net_nfc_response_get_atr_t *)(msg->detail_message))->user_param);
- }
- else
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_get_atr_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_atr_t *)(msg->detail_message))->user_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_NOTIFY :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_notify_t *)msg->detail_message)->result, NULL, client_context->register_user_param, NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_TRANSCEIVE :
- {
- data_s *data = &(((net_nfc_response_transceive_t *)msg->detail_message)->data);
-
- if (data->length > 0)
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_transceive_t *)msg->detail_message)->result, (void *)data, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param);
- }
- else
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_transceive_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_make_read_only_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_make_read_only_ndef_t *)(msg->detail_message))->trans_param);
- }
- break;
-
- case NET_NFC_MESSAGE_IS_TAG_CONNECTED :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_is_tag_connected_t *)msg->detail_message)->result, (void *)&(((net_nfc_response_is_tag_connected_t *)msg->detail_message)->devType), client_context->register_user_param, ((net_nfc_response_is_tag_connected_t *)(msg->detail_message))->trans_param);
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF :
- {
- data_s *data = &(((net_nfc_response_read_ndef_t *)msg->detail_message)->data);
- ndef_message_s *ndef = NULL;
-
- if (net_nfc_util_create_ndef_message(&ndef) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("memory alloc fail..");
- break;
- }
-
- if (data->length > 0 && net_nfc_util_convert_rawdata_to_ndef_message(data, ndef) == NET_NFC_OK)
- {
- if(client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_read_ndef_t *)msg->detail_message)->result, ndef, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param);
- }
- else
- {
- if(client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_read_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param);
- }
- net_nfc_util_free_ndef_message(ndef);
- }
- break;
-
- case NET_NFC_GET_SERVER_STATE :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state);
- }
- break;
-
- case NET_NFC_MESSAGE_SIM_TEST :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state);
- }
- break;
-
- case NET_NFC_MESSAGE_PRBS_TEST :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state);
- }
- break;
-
- case NET_NFC_MESSAGE_SET_EEDATA :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_get_server_state_t *)msg->detail_message)->result, NULL, client_context->register_user_param, (void *)((net_nfc_response_get_server_state_t *)msg->detail_message)->state);
- }
- break;
-
- case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION :
- {
- data_s *version = &(((net_nfc_response_firmware_version_t *)msg->detail_message)->data);
-
- if (version->length > 0)
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, version, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param);
- }
- else
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_send_apdu_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_send_apdu_t *)(msg->detail_message))->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_WRITE_NDEF :
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, ((net_nfc_response_write_ndef_t *)msg->detail_message)->result, NULL, client_context->register_user_param, ((net_nfc_response_transceive_t *)(msg->detail_message))->trans_param);
- }
- break;
-
- case NET_NFC_MESSAGE_TAG_DISCOVERED :
- {
- net_nfc_response_tag_discovered_t *detected = (net_nfc_response_tag_discovered_t *)msg->detail_message;
-
- if (net_nfc_util_check_tag_filter(detected->devType) == false)
- {
- DEBUG_CLIENT_MSG("The detected target is filtered out");
- }
-
-#ifdef SAVE_TARGET_INFO_IN_CC
- __net_nfc_clear_tag_info_cache(client_context);
-
- net_nfc_tag_info_s *list = NULL;
- net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list);
-
- net_nfc_target_info_s *info = NULL;
- _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s));
- if (info == NULL)
- {
- DEBUG_CLIENT_MSG("mem alloc is failed");
- _net_nfc_util_free_mem(list);
- break;
- }
-
- info->ndefCardState = detected->ndefCardState;
- info->actualDataSize = detected->actualDataSize;
- info->maxDataSize = detected->maxDataSize;
- info->devType = detected->devType;
- info->handle = detected->handle;
- info->is_ndef_supported = detected->is_ndef_supported;
- info->number_of_keys = detected->number_of_keys;
- info->tag_info_list = list;
- info->raw_data = detected->raw_data;
-
- client_context->target_info = info;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, NET_NFC_OK, info, client_context->register_user_param, NULL);
-#else
- net_nfc_tag_info_s *list = NULL;
- net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list);
-
- net_nfc_target_info_s info;
- memset(&info, 0x00, sizeof(net_nfc_target_info_s));
-
- info.ndefCardState = detected->ndefCardState;
- info.actualDataSize = detected->actualDataSize;
- info.maxDataSize = detected->maxDataSize;
- info.devType = detected->devType;
- info.handle = detected->handle;
- info.is_ndef_supported = detected->is_ndef_supported;
- info.number_of_keys = detected->number_of_keys;
- info.tag_info_list = list;
- info.raw_data = detected.raw_data;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, NET_NFC_OK, &info, client_context->register_user_param, NULL);
-
- net_nfc_util_release_tag_info(&info);
-#endif
- }
- break;
-
- case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO :
- {
- net_nfc_response_get_current_tag_info_t *detected = (net_nfc_response_get_current_tag_info_t *)msg->detail_message;
-
- if (detected->result != NET_NFC_NOT_CONNECTED)
- {
- if (net_nfc_util_check_tag_filter(detected->devType) == false)
- {
- DEBUG_CLIENT_MSG("The detected target is filtered out");
- }
-
-#ifdef SAVE_TARGET_INFO_IN_CC
- __net_nfc_clear_tag_info_cache(client_context);
-
- net_nfc_tag_info_s *list = NULL;
- net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list);
-
- net_nfc_target_info_s *info = NULL;
- _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s));
- if (info == NULL)
- {
- DEBUG_CLIENT_MSG("mem alloc is failed");
- _net_nfc_util_free_mem(list);
- break;
- }
-
- info->ndefCardState = detected->ndefCardState;
- info->actualDataSize = detected->actualDataSize;
- info->maxDataSize = detected->maxDataSize;
- info->devType = detected->devType;
- info->handle = detected->handle;
- info->is_ndef_supported = detected->is_ndef_supported;
- info->number_of_keys = detected->number_of_keys;
- info->tag_info_list = list;
- info->raw_data = detected->raw_data;
-
- client_context->target_info = info;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, NET_NFC_OK, info, client_context->register_user_param, detected->trans_param);
-#else
- net_nfc_tag_info_s *list = NULL;
- net_nfc_get_tag_info_list(&(detected->target_info_values), detected->number_of_keys, &list);
-
- net_nfc_target_info_s info;
- memset(&info, 0x00, sizeof(net_nfc_target_info_s));
-
- info.ndefCardState = detected->ndefCardState;
- info.actualDataSize = detected->actualDataSize;
- info.maxDataSize = detected->maxDataSize;
- info.devType = detected->devType;
- info.handle = detected->handle;
- info.is_ndef_supported = detected->is_ndef_supported;
- info.number_of_keys = detected->number_of_keys;
- info.tag_info_list = list;
- info.raw_data = detected.raw_data;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, NET_NFC_OK, &info, client_context->register_user_param, detected->trans_param);
-
- net_nfc_util_release_tag_info(&info);
-#endif
- }
- else
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, detected->result, NULL, client_context->register_user_param, detected->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE :
- {
- net_nfc_response_get_current_target_handle_t *detected = (net_nfc_response_get_current_target_handle_t *)msg->detail_message;
-
- if (detected->result == NET_NFC_OK)
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, detected->result, (void *)detected->handle, client_context->register_user_param, detected->trans_param);
- }
- else
- {
- if (client_cb != NULL)
- client_cb(msg->response_type, detected->result, NULL, client_context->register_user_param, detected->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_TAG_DETACHED :
- {
- net_nfc_response_target_detached_t *detached = (net_nfc_response_target_detached_t *)msg->detail_message;
-
- if (net_nfc_util_check_tag_filter(detached->devType) == false)
- {
- DEBUG_CLIENT_MSG("The detected target is filtered out");
- }
-
- if (client_cb != NULL)
- client_cb(msg->response_type, NET_NFC_OK, (net_nfc_target_handle_h)detached->handle, client_context->register_user_param, NULL);
-
-#ifdef SAVE_TARGET_INFO_IN_CC
- __net_nfc_clear_tag_info_cache(client_context);
-#endif
- }
- break;
-
- case NET_NFC_MESSAGE_FORMAT_NDEF :
- {
- net_nfc_response_format_ndef_t *detail_msg = (net_nfc_response_format_ndef_t *)msg->detail_message;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, detail_msg->trans_param);
- }
- break;
-
- case NET_NFC_MESSAGE_SE_START_TRANSACTION :
- case NET_NFC_MESSAGE_SE_END_TRANSACTION :
- case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION :
- case NET_NFC_MESSAGE_SE_CONNECTIVITY :
- case NET_NFC_MESSAGE_SE_FIELD_ON :
- case NET_NFC_MESSAGE_SE_FIELD_OFF :
- {
- net_nfc_response_se_event_t *se_event = (net_nfc_response_se_event_t *)msg->detail_message;
- net_nfc_se_event_info_s info = { { 0, }, };
-
- info.aid = se_event->aid;
- info.param = se_event->param;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, NET_NFC_OK, (void *)&info, client_context->register_user_param, NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_LISTEN :
- {
- net_nfc_response_listen_socket_t *detail_msg = (net_nfc_response_listen_socket_t *)msg->detail_message;
- net_nfc_llcp_internal_socket_s *psocket_info = NULL;
-
- psocket_info = _find_internal_socket_info(detail_msg->client_socket);
- if (psocket_info == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned from server..");
- break;
- }
- psocket_info->oal_socket = detail_msg->oal_socket;
- DEBUG_CLIENT_MSG ("oal socket %d", detail_msg->oal_socket);
- if (psocket_info->cb != NULL)
- {
- psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONNECT :
- {
- net_nfc_response_connect_socket_t *detail_msg = (net_nfc_response_connect_socket_t *)msg->detail_message;
- net_nfc_llcp_internal_socket_s *psocket_info = NULL;
-
- psocket_info = _find_internal_socket_info(detail_msg->client_socket);
- if (psocket_info == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned from server..");
- break;
- }
- psocket_info->oal_socket = detail_msg->oal_socket;
- if (psocket_info->cb != NULL)
- {
- psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONNECT_SAP :
- {
- net_nfc_response_connect_sap_socket_t *detail_msg = (net_nfc_response_connect_sap_socket_t *)msg->detail_message;
- net_nfc_llcp_internal_socket_s *psocket_info = NULL;
-
- psocket_info = _find_internal_socket_info(detail_msg->client_socket);
- if (psocket_info == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned from server..");
- break;
- }
- psocket_info->oal_socket = detail_msg->oal_socket;
- if (psocket_info->cb != NULL)
- {
- psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_SEND :
- {
- net_nfc_response_send_socket_t *detail_msg = (net_nfc_response_send_socket_t *)msg->detail_message;
- net_nfc_llcp_internal_socket_s *psocket_info = NULL;
-
- psocket_info = _find_internal_socket_info(detail_msg->client_socket);
- if (psocket_info == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned from server..");
- break;
- }
- if (psocket_info->cb != NULL)
- {
- psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE :
- {
- net_nfc_response_receive_socket_t *detail_msg = (net_nfc_response_receive_socket_t *)msg->detail_message;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, detail_msg->result, &(detail_msg->data), client_context->register_user_param, NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_RECEIVE :
- {
- net_nfc_response_p2p_receive_t *detail_msg = (net_nfc_response_p2p_receive_t *)msg->detail_message;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, detail_msg->result, &(detail_msg->data), client_context->register_user_param, NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_SEND :
- {
- net_nfc_response_p2p_send_t *detail_msg = (net_nfc_response_p2p_send_t *)msg->detail_message;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_DISCONNECT :
- {
- net_nfc_response_disconnect_socket_t *detail_msg = (net_nfc_response_disconnect_socket_t *)msg->detail_message;
- net_nfc_llcp_internal_socket_s *psocket_info = NULL;
-
- psocket_info = _find_internal_socket_info(detail_msg->client_socket);
- if (psocket_info == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned from server..");
- break;
- }
- if (psocket_info->cb != NULL)
- {
- psocket_info->cb(msg->response_type, detail_msg->result, NULL, psocket_info->register_param, detail_msg->trans_param);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONFIG :
- {
- net_nfc_response_config_llcp_t *detail_msg = (net_nfc_response_config_llcp_t *)msg->detail_message;
-
- if (client_cb != NULL)
- client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_ERROR :
- {
- net_nfc_response_llcp_socket_error_t *detail_msg = (net_nfc_response_llcp_socket_error_t *)msg->detail_message;
- net_nfc_llcp_internal_socket_s *psocket_info = NULL;
-
- psocket_info = _find_internal_socket_info(detail_msg->client_socket);
- if (psocket_info == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned from server..");
- break;
- }
- if (psocket_info->cb != NULL)
- {
- psocket_info->cb(msg->response_type, detail_msg->error, NULL, psocket_info->register_param, NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_ACCEPTED :
- {
- net_nfc_response_incomming_llcp_t *detail_msg = (net_nfc_response_incomming_llcp_t *)msg->detail_message;
- net_nfc_llcp_internal_socket_s *psocket_info = NULL;
- psocket_info = _find_internal_socket_info_by_oal_socket(detail_msg->oal_socket);
- if (psocket_info == NULL)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned from server..");
- break;
- }
- if (psocket_info->cb != NULL)
- {
- net_nfc_llcp_internal_socket_s *socket_data = NULL;
- _net_nfc_util_alloc_mem(socket_data, sizeof(net_nfc_llcp_internal_socket_s));
- socket_data->client_socket = socket_handle++;
- socket_data->miu = detail_msg->option.miu;
- socket_data->rw = detail_msg->option.rw;
- socket_data->type = detail_msg->option.type;
- socket_data->device_id = detail_msg->handle;
- socket_data->close_requested = false;
- socket_data->oal_socket = detail_msg->incomming_socket;
- _append_internal_socket(socket_data);
- psocket_info->cb(msg->response_type, detail_msg->result, (void *)&(socket_data->client_socket), psocket_info->register_param, NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_DISCOVERED :
- {
- net_nfc_response_llcp_discovered_t *detail_msg = (net_nfc_response_llcp_discovered_t *)msg->detail_message;
-
- _net_nfc_set_llcp_current_target_id(detail_msg->handle);
- _net_nfc_set_llcp_remote_configure(&(detail_msg->llcp_config_info));
-
- __net_nfc_clear_tag_info_cache(client_context);
-
- net_nfc_tag_info_s *list = NULL;
- net_nfc_get_tag_info_list(&(detail_msg->target_info_values), detail_msg->number_of_keys, &list);
-
- net_nfc_target_info_s *info = NULL;
- if ((info = calloc(1, sizeof(net_nfc_target_info_s))) == NULL)
- {
- DEBUG_CLIENT_MSG("mem alloc is failed");
- _net_nfc_util_free_mem(list);
- break;
- }
-
- info->actualDataSize = 0;
- info->maxDataSize = 0;
- info->devType = detail_msg->devType;
- info->handle = detail_msg->handle;
- info->is_ndef_supported = false;
- info->number_of_keys = detail_msg->number_of_keys;
- info->tag_info_list = list;
-
- client_context->target_info = info;
-
- if (client_cb != NULL)
- {
- client_cb(msg->response_type, NET_NFC_OK, (void *)info, client_context->register_user_param, NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_DETACHED :
- {
- net_nfc_response_llcp_detached_t *detail_msg = (net_nfc_response_llcp_detached_t *)msg->detail_message;
-
- _net_nfc_set_llcp_current_target_id(NULL);
-
- if (client_cb != NULL)
- {
- client_cb(msg->response_type, detail_msg->result, NULL, client_context->register_user_param, NULL);
- }
- _net_nfc_llcp_close_all_socket();
-
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_DISCOVERED :
- {
- net_nfc_response_p2p_discovered_t *detail_msg = (net_nfc_response_p2p_discovered_t *)msg->detail_message;
-
- if (client_cb != NULL)
- {
- client_cb(msg->response_type, detail_msg->result, (void *)detail_msg->handle, client_context->register_user_param, NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
- {
- net_nfc_response_connection_handover_t *detail_msg = (net_nfc_response_connection_handover_t *)msg->detail_message;
-
- if (detail_msg == NULL)
- {
- DEBUG_ERR_MSG("NET_NFC_MESSAGE_CONNECTION_HANDOVER detail_msg == NULL");
- break;
- }
-
- if (client_cb != NULL)
- {
- net_nfc_connection_handover_info_s info = { 0, };
-
- info.type = detail_msg->type;
- info.data.length = detail_msg->data.length;
- if (info.data.length > 0)
- {
- _net_nfc_util_alloc_mem(info.data.buffer, info.data.length);
- if (info.data.buffer == NULL)
- {
- DEBUG_ERR_MSG("mem alloc is failed");
- break;
- }
- memcpy(info.data.buffer, detail_msg->data.buffer, info.data.length);
- }
-
- client_cb(msg->response_type, detail_msg->event, (void *)&info, client_context->register_user_param, NULL);
-
- if (info.data.length > 0)
- {
- _net_nfc_util_free_mem(info.data.buffer);
- }
- }
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_INIT :
- {
- net_nfc_response_test_t *detail_msg = (net_nfc_response_test_t *)msg->detail_message;
-
- DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_SERVICE_INIT [%p]", detail_msg->trans_param);
-
- if (client_cb != NULL)
- {
- client_cb(NET_NFC_MESSAGE_INIT, detail_msg->result, NULL, client_context->register_user_param, NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_DEINIT :
- {
- net_nfc_response_test_t *detail_msg = (net_nfc_response_test_t *)msg->detail_message;
-
- DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_SERVICE_DEINIT [%p]", detail_msg->trans_param);
-
- if (client_cb != NULL)
- {
- client_cb(NET_NFC_MESSAGE_DEINIT, detail_msg->result, NULL, client_context->register_user_param, NULL);
- }
- }
- break;
-
- default :
- break;
- }
-
- /* client callback must copy data to client area */
- net_nfc_util_mem_free_detail_msg(NET_NFC_UTIL_MSG_TYPE_RESPONSE, msg->response_type, msg->detail_message);
- _net_nfc_util_free_mem(msg);
-
- return false;
-}
-
-net_nfc_error_e net_nfc_client_dispatch_sync_response(net_nfc_response_msg_t *msg)
-{
- net_nfc_error_e result = NET_NFC_OK;
-// client_context_t *client_context = NULL;
-
- DEBUG_CLIENT_MSG("synchronous callback, message = [%d]", msg->response_type);
-
-// client_context = net_nfc_get_client_context();
-
- switch (msg->response_type)
- {
- case NET_NFC_MESSAGE_GET_SE :
- break;
-
- case NET_NFC_MESSAGE_SET_SE :
- break;
-
- case NET_NFC_MESSAGE_SE_TYPE_CHANGED :
- break;
-
- case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
- {
- net_nfc_response_open_internal_se_t *response = (net_nfc_response_open_internal_se_t *)msg->detail_message;
- net_nfc_target_handle_h *handle = (net_nfc_target_handle_h *)response->user_param;
-
- /* return */
- result = response->result;
-
- if (handle != NULL) {
- *handle = (net_nfc_target_handle_h)response->handle;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
- {
- net_nfc_response_close_internal_se_t *response = (net_nfc_response_close_internal_se_t *)msg->detail_message;
-
- /* return */
- result = response->result;
- }
- break;
-
- case NET_NFC_MESSAGE_SEND_APDU_SE :
- {
- net_nfc_response_send_apdu_t *response = (net_nfc_response_send_apdu_t *)msg->detail_message;
- data_h *data = (data_h *)response->user_param;
-
- /* return */
- result = response->result;
-
- if (data != NULL && response->data.buffer != NULL &&
- response->data.length > 0) {
- net_nfc_create_data(data, response->data.buffer,
- response->data.length);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_GET_ATR_SE :
- {
- net_nfc_response_get_atr_t *response = (net_nfc_response_get_atr_t *)msg->detail_message;
- data_h *data = (data_h *)response->user_param;
-
- /* return */
- result = response->result;
-
- if (data != NULL && response->data.buffer != NULL &&
- response->data.length > 0) {
- net_nfc_create_data(data, response->data.buffer,
- response->data.length);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_NOTIFY :
- break;
-
- case NET_NFC_MESSAGE_TRANSCEIVE :
- break;
-
- case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF :
- break;
-
- case NET_NFC_MESSAGE_IS_TAG_CONNECTED :
- {
- net_nfc_response_is_tag_connected_t *response = (net_nfc_response_is_tag_connected_t *)msg->detail_message;
- net_nfc_response_is_tag_connected_t *context = (net_nfc_response_is_tag_connected_t *)response->trans_param;
-
- /* return */
- result = response->result;
-
- if (context != NULL)
- {
- context->result = response->result;
- context->devType = response->devType;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF :
- break;
-
- case NET_NFC_GET_SERVER_STATE :
- break;
-
- case NET_NFC_MESSAGE_SIM_TEST :
- break;
-
- case NET_NFC_MESSAGE_PRBS_TEST :
- break;
-
- case NET_NFC_MESSAGE_SET_EEDATA :
- break;
-
- case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION :
- break;
-
- case NET_NFC_MESSAGE_WRITE_NDEF :
- break;
-
- case NET_NFC_MESSAGE_TAG_DISCOVERED :
- break;
-
- case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO :
- {
- net_nfc_response_get_current_tag_info_t *response = (net_nfc_response_get_current_tag_info_t *)msg->detail_message;
- net_nfc_response_get_current_tag_info_t *context = (net_nfc_response_get_current_tag_info_t *)response->trans_param;
-
- /* return */
- result = response->result;
-
- if (context != NULL)
- {
- context->result = response->result;
-
- if (response->result != NET_NFC_NOT_CONNECTED)
- {
- if (net_nfc_util_check_tag_filter(response->devType) == true)
- {
- net_nfc_target_info_s *info = NULL;
-
- _net_nfc_util_alloc_mem(info, sizeof(net_nfc_target_info_s));
-
- info->ndefCardState = response->ndefCardState;
- info->actualDataSize = response->actualDataSize;
- info->maxDataSize = response->maxDataSize;
- info->devType = response->devType;
- info->handle = response->handle;
- info->is_ndef_supported = response->is_ndef_supported;
- info->number_of_keys = response->number_of_keys;
- net_nfc_get_tag_info_list(&(response->target_info_values), response->number_of_keys, &info->tag_info_list);
- if (response->raw_data.length > 0)
- {
- net_nfc_util_alloc_data(&info->raw_data, response->raw_data.length);
- memcpy(info->raw_data.buffer, response->raw_data.buffer, info->raw_data.length);
- }
-
- context->trans_param = info;
- }
- else
- {
- /* filtered tag */
- }
- }
- }
- }
- break;
-
- case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE :
- {
- net_nfc_response_get_current_target_handle_t *response = (net_nfc_response_get_current_target_handle_t *)msg->detail_message;
- net_nfc_response_get_current_target_handle_t *context = (net_nfc_response_get_current_target_handle_t *)response->trans_param;
-
- /* return */
- result = response->result;
-
- if (context != NULL)
- {
- context->handle = response->handle;
- context->result = response->result;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_TAG_DETACHED :
- break;
-
- case NET_NFC_MESSAGE_FORMAT_NDEF :
- break;
-
- case NET_NFC_MESSAGE_SE_START_TRANSACTION :
- case NET_NFC_MESSAGE_SE_END_TRANSACTION :
- case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION :
- case NET_NFC_MESSAGE_SE_CONNECTIVITY :
- case NET_NFC_MESSAGE_SE_FIELD_ON :
- case NET_NFC_MESSAGE_SE_FIELD_OFF :
- break;
-
- case NET_NFC_MESSAGE_LLCP_LISTEN :
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONNECT :
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONNECT_SAP :
- break;
-
- case NET_NFC_MESSAGE_LLCP_SEND :
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE :
- break;
-
- case NET_NFC_MESSAGE_P2P_RECEIVE :
- break;
-
- case NET_NFC_MESSAGE_P2P_SEND :
- break;
-
- case NET_NFC_MESSAGE_LLCP_DISCONNECT :
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONFIG :
- break;
-
- case NET_NFC_MESSAGE_LLCP_ERROR :
- break;
-
- case NET_NFC_MESSAGE_LLCP_ACCEPTED :
- break;
-
- case NET_NFC_MESSAGE_LLCP_DISCOVERED :
- break;
-
- case NET_NFC_MESSAGE_P2P_DETACHED :
- break;
-
- case NET_NFC_MESSAGE_P2P_DISCOVERED :
- break;
-
- case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
- break;
-
- case NET_NFC_MESSAGE_SERVICE_INIT :
- break;
-
- case NET_NFC_MESSAGE_SERVICE_DEINIT :
- break;
-
- default :
- break;
- }
-
- /* client callback must copy data to client area */
- net_nfc_util_mem_free_detail_msg(NET_NFC_UTIL_MSG_TYPE_RESPONSE, msg->response_type, msg->detail_message);
- _net_nfc_util_free_mem(msg);
-
- return result;
-}
-
-static net_nfc_error_e net_nfc_get_tag_info_list(data_s *values, int number_of_keys, net_nfc_tag_info_s **list)
-{
- net_nfc_tag_info_s *temp_list = NULL;
-
- if (list == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- /* TODO */
- _net_nfc_util_alloc_mem(temp_list, number_of_keys * sizeof(net_nfc_tag_info_s));
- if (temp_list == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- *list = temp_list;
-
- /* get 1 byte :: length
- * get key name
- * get 1 byte :: value length
- * make data_h
- */
- uint8_t *pBuffer = values->buffer;
-
- if (pBuffer == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- int index = 0;
-
- while (index < number_of_keys)
- {
- int key_length = *pBuffer;
- char *key = NULL;
-
- _net_nfc_util_alloc_mem(key, key_length + 1);
- if (key == NULL)
- return NET_NFC_ALLOC_FAIL;
- pBuffer = pBuffer + 1;
-
- /* copy key name */
- memcpy(key, pBuffer, key_length);
- pBuffer = pBuffer + key_length;
-
- DEBUG_CLIENT_MSG("key = [%s]", key);
-
- /* get values length */
- uint32_t value_length = *pBuffer;
- pBuffer = pBuffer + 1;
-
- data_h value = NULL;
-
- if (value_length > 0)
- {
- net_nfc_create_data(&value, pBuffer, value_length);
- pBuffer = pBuffer + value_length;
- }
-
- temp_list->key = key;
- temp_list->value = value;
-
- temp_list++;
-
- index++;
- }
- return NET_NFC_OK;
-}
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
#include <pthread.h>
-#include "net_nfc_exchanger.h"
-#include "net_nfc_exchanger_private.h"
-#include "net_nfc.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_client_ipc_private.h"
-#include "net_nfc_client_nfc_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_data.h"
+#include "net_nfc_client_context.h"
+#include "net_nfc_client_p2p.h"
+#include "net_nfc_client_handover.h"
+#include "net_nfc_client_exchanger.h"
-static net_nfc_exchanger_cb exchanger_cb = NULL;
+static net_nfc_exchanger_cb gdbus_exch_cb = NULL;
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
#endif
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_exchanger_data(net_nfc_exchanger_data_h *ex_data, data_h payload)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_create_exchanger_data(
+ net_nfc_exchanger_data_h *ex_data,
+ data_h payload)
{
net_nfc_exchanger_data_s* tmp_ex_data = NULL;
return NET_NFC_NULL_PARAMETER;
}
- _net_nfc_util_alloc_mem(tmp_ex_data, sizeof(net_nfc_exchanger_data_s));
+ _net_nfc_util_alloc_mem(
+ tmp_ex_data,
+ sizeof(net_nfc_exchanger_data_s));
+
if (tmp_ex_data == NULL)
{
return NET_NFC_ALLOC_FAIL;
tmp_ex_data->type = NET_NFC_EXCHANGER_RAW;
- _net_nfc_util_alloc_mem(tmp_ex_data->binary_data.buffer, ((data_s *)payload)->length);
+ _net_nfc_util_alloc_mem(
+ tmp_ex_data->binary_data.buffer,
+ ((data_s *)payload)->length);
+
if (tmp_ex_data->binary_data.buffer == NULL)
{
_net_nfc_util_free_mem(tmp_ex_data);
return NET_NFC_ALLOC_FAIL;
}
- memcpy(tmp_ex_data->binary_data.buffer, ((data_s *)payload)->buffer, ((data_s *)payload)->length);
+ memcpy(tmp_ex_data->binary_data.buffer,
+ ((data_s *)payload)->buffer,
+ ((data_s *)payload)->length);
tmp_ex_data->binary_data.length = ((data_s *)payload)->length;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_exchanger_data(net_nfc_exchanger_data_h ex_data)
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_free_exchanger_data(
+ net_nfc_exchanger_data_h ex_data)
{
if (ex_data == NULL)
{
if (((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer != NULL)
{
- _net_nfc_util_free_mem(((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer);
+ _net_nfc_util_free_mem(
+ ((net_nfc_exchanger_data_s *)ex_data)->binary_data.buffer);
}
_net_nfc_util_free_mem(ex_data);
return NET_NFC_OK;
}
-net_nfc_exchanger_cb net_nfc_get_exchanger_cb()
+NET_NFC_EXPORT_API
+net_nfc_exchanger_cb net_nfc_client_get_exchanger_cb()
{
- return exchanger_cb;
+ return gdbus_exch_cb;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_exchanger_cb()
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_unset_exchanger_cb()
{
- client_context_t* client_context = net_nfc_get_client_context();
- if (exchanger_cb == NULL)
+ if (gdbus_exch_cb == NULL)
{
return NET_NFC_NOT_REGISTERED;
}
- if (client_context != NULL)
- pthread_mutex_lock(&(client_context->g_client_lock));
- exchanger_cb = NULL;
- if (client_context != NULL)
- pthread_mutex_unlock(&(client_context->g_client_lock));
+ gdbus_exch_cb = NULL;
- net_nfc_state_deactivate();
- net_nfc_deinitialize();
+ net_nfc_client_deinitialize();
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_exchanger_data(net_nfc_exchanger_data_h ex_handle, net_nfc_target_handle_h target_handle, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_send_exchanger_data(
+ net_nfc_exchanger_data_h ex_handle,
+ net_nfc_target_handle_h target_handle,
+ void* trans_param)
{
net_nfc_error_e ret;
- net_nfc_request_p2p_send_t *request = NULL;
- uint32_t length = 0;
net_nfc_exchanger_data_s *ex_data = (net_nfc_exchanger_data_s *)ex_handle;
- DEBUG_CLIENT_MSG("send reqeust :: exchanger data = [%p] target_handle = [%p]", ex_handle, target_handle);
-
- length = sizeof(net_nfc_request_p2p_send_t) + ex_data->binary_data.length;
-
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_P2P_SEND;
- request->handle = (net_nfc_target_handle_s *)target_handle;
- request->data_type = ex_data->type;
- request->data.length = ex_data->binary_data.length;
- request->user_param = (uint32_t)trans_param;
+ DEBUG_CLIENT_MSG("send reqeust :: exchanger data = "
+ "[%p] target_handle = [%p]", ex_handle, target_handle);
- memcpy(&request->data.buffer, ex_data->binary_data.buffer, request->data.length);
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
-
- _net_nfc_util_free_mem(request);
+ /*Sync call is used because there is no callback provided*/
+ ret = net_nfc_client_p2p_send_sync(ex_data,target_handle);
return ret;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_request_connection_handover(net_nfc_target_handle_h target_handle, net_nfc_conn_handover_carrier_type_e type)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_exchanger_request_connection_handover(
+ net_nfc_target_handle_h target_handle,
+ net_nfc_conn_handover_carrier_type_e type)
{
net_nfc_error_e ret = NET_NFC_UNKNOWN_ERROR;
- net_nfc_request_connection_handover_t *request = NULL;
- uint32_t length = 0;
+ net_nfc_conn_handover_carrier_type_e carrier_type;
+ data_h data = NULL;
if (target_handle == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- length = sizeof(net_nfc_request_p2p_send_t);
-
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_CONNECTION_HANDOVER;
- request->handle = (net_nfc_target_handle_s *)target_handle;
- request->type = type;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
-
- _net_nfc_util_free_mem(request);
+ ret = net_nfc_client_p2p_connection_handover_sync(target_handle,
+ type,
+ &carrier_type,
+ &data);
return ret;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_type(net_nfc_connection_handover_info_h info_handle, net_nfc_conn_handover_carrier_type_e *type)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_type(
+ net_nfc_connection_handover_info_h info_handle,
+ net_nfc_conn_handover_carrier_type_e *type)
{
net_nfc_connection_handover_info_s *info = NULL;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_get_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle, data_h *data)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_exchanger_get_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle,
+ data_h *data)
{
net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
net_nfc_connection_handover_info_s *info = NULL;
return result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_exchanger_free_alternative_carrier_data(net_nfc_connection_handover_info_h info_handle)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_exchanger_free_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle)
{
net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
net_nfc_connection_handover_info_s *info = NULL;
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_data.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_handover.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+typedef struct _HandoverFuncData HandoverFuncData;
+
+struct _HandoverFuncData
+{
+ gpointer handover_callback;
+ gpointer handover_data;
+};
+
+static NetNfcGDbusHandover *handover_proxy = NULL;
+
+static void p2p_connection_handover(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void p2p_connection_handover(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ HandoverFuncData *func_data;
+ GVariant *data;
+ GError *error = NULL;
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_exchanger_event_e event;
+ net_nfc_conn_handover_carrier_type_e type;
+ data_s arg_data;
+
+ net_nfc_p2p_connection_handover_completed_cb callback;
+
+ if(net_nfc_gdbus_handover_call_request_finish (handover_proxy,
+ (gint32 *)&event,
+ (gint32 *)&type,
+ &data,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish"
+ " connection handover: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ func_data = user_data;
+ if(func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get HandoverFuncData");
+ return;
+ }
+
+ if(func_data->handover_callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(data, &arg_data);
+
+ callback = (net_nfc_p2p_connection_handover_completed_cb)
+ func_data->handover_callback;
+
+ callback(result,
+ type,
+ &arg_data,
+ func_data->handover_data);
+
+ net_nfc_util_free_data(&arg_data);
+
+ g_free(func_data);
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_handover_free_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ if (info->data.buffer != NULL)
+ {
+ _net_nfc_util_free_mem(info->data.buffer);
+ }
+
+ _net_nfc_util_free_mem(info);
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type(
+ net_nfc_connection_handover_info_h info_handle,
+ net_nfc_conn_handover_carrier_type_e *type)
+{
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL || type == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ *type = info->type;
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_data(
+ net_nfc_connection_handover_info_h info_handle,
+ data_h *data)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ net_nfc_connection_handover_info_s *info = NULL;
+
+ if (info_handle == NULL || data == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ info = (net_nfc_connection_handover_info_s *)info_handle;
+
+ result = net_nfc_create_data(data, info->data.buffer, info->data.length);
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_p2p_connection_handover(
+ net_nfc_target_handle_h handle,
+ net_nfc_conn_handover_carrier_type_e arg_type,
+ net_nfc_p2p_connection_handover_completed_cb callback,
+ void *cb_data)
+{
+
+ HandoverFuncData *funcdata = NULL;
+ net_nfc_target_handle_s *tag_handle = (net_nfc_target_handle_s *)handle;
+
+ if(handover_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get handover Proxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ funcdata = g_new0(HandoverFuncData, 1);
+ if (funcdata == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ funcdata->handover_callback = (gpointer)callback;
+ funcdata->handover_data = cb_data;
+
+ net_nfc_gdbus_handover_call_request(handover_proxy,
+ GPOINTER_TO_UINT(tag_handle),
+ arg_type,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ p2p_connection_handover,
+ funcdata);
+
+ return NET_NFC_OK;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_p2p_connection_handover_sync(
+ net_nfc_target_handle_h handle,
+ net_nfc_conn_handover_carrier_type_e arg_type,
+ net_nfc_conn_handover_carrier_type_e *out_carrier,
+ data_h *out_ac_data)
+{
+
+ net_nfc_target_handle_s *tag_handle = (net_nfc_target_handle_s *)handle;
+ GError *error = NULL;
+ GVariant *out_data;
+ net_nfc_exchanger_event_e out_event;
+ net_nfc_conn_handover_carrier_type_e out_type;
+
+ if(handover_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get handover Proxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if(net_nfc_gdbus_handover_call_request_sync(handover_proxy,
+ GPOINTER_TO_UINT(tag_handle),
+ arg_type,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint32 *)&out_event,
+ (gint32 *)&out_type,
+ &out_data,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("handover (sync call) failed: %s",error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (out_carrier)
+ {
+ *out_carrier = out_type;
+ }
+
+ if (out_ac_data)
+ {
+ *out_ac_data = net_nfc_util_gdbus_variant_to_data(out_data);
+ }
+
+ return NET_NFC_OK;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_handover_init(void)
+{
+ GError *error = NULL;
+
+ if (handover_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+ return NET_NFC_OK;
+ }
+
+ handover_proxy = net_nfc_gdbus_handover_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Handover",
+ NULL,
+ &error);
+
+ if(handover_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+void net_nfc_client_handover_deinit(void)
+{
+ if(handover_proxy)
+ {
+ g_object_unref(handover_proxy);
+ handover_proxy = NULL;
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-#include <pthread.h>
-
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_client_ipc_private.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_secure_element_type(net_nfc_se_type_e se_type, void *trans_param)
-{
- net_nfc_error_e ret;
- net_nfc_request_set_se_t request = { 0, };
-
- if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC)
- {
- return NET_NFC_INVALID_PARAM;
- }
-
- request.length = sizeof(net_nfc_request_set_se_t);
- request.request_type = NET_NFC_MESSAGE_SET_SE;
- request.se_type = se_type;
- request.trans_param = trans_param;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_secure_element_type(void *trans_param)
-{
- net_nfc_error_e ret;
- net_nfc_request_get_se_t request = { 0, };
-
- request.length = sizeof(net_nfc_request_get_se_t);
- request.request_type = NET_NFC_MESSAGE_GET_SE;
- request.trans_param = trans_param;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_open_internal_secure_element(net_nfc_se_type_e se_type, void *trans_param)
-{
- net_nfc_error_e ret;
- net_nfc_request_open_internal_se_t request = { 0, };
-
- if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC)
- {
- return NET_NFC_INVALID_PARAM;
- }
-
- request.length = sizeof(net_nfc_request_open_internal_se_t);
- request.request_type = NET_NFC_MESSAGE_OPEN_INTERNAL_SE;
- request.se_type = se_type;
- request.trans_param = trans_param;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_open_internal_secure_element_sync(net_nfc_se_type_e se_type, net_nfc_target_handle_h *handle)
-{
- net_nfc_request_open_internal_se_t request = { 0, };
- net_nfc_target_handle_h temp = NULL;
- net_nfc_error_e result;
-
- if (se_type < NET_NFC_SE_TYPE_NONE || se_type > NET_NFC_SE_TYPE_UICC) {
- return NET_NFC_INVALID_PARAM;
- }
-
- request.length = sizeof(net_nfc_request_open_internal_se_t);
- request.request_type = NET_NFC_MESSAGE_OPEN_INTERNAL_SE;
- request.se_type = se_type;
- request.user_param = (uint32_t)&temp;
-
- result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL);
- if (result == NET_NFC_OK) {
- if (temp != NULL) {
- *handle = temp;
- } else {
- DEBUG_ERR_MSG("NULL handle returned data returned");
- result = NET_NFC_OPERATION_FAIL;
- }
- } else{
- DEBUG_ERR_MSG("net_nfc_client_send_request_sync failed [%d]", result);
- }
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_internal_secure_element(net_nfc_target_handle_h handle, void *trans_param)
-{
- net_nfc_error_e ret;
- net_nfc_request_close_internal_se_t request = { 0, };
-
- if (handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- request.length = sizeof(net_nfc_request_close_internal_se_t);
- request.request_type = NET_NFC_MESSAGE_CLOSE_INTERNAL_SE;
- request.handle = (net_nfc_target_handle_s *)handle;
- request.trans_param = trans_param;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_internal_secure_element_sync(net_nfc_target_handle_h handle)
-{
- net_nfc_error_e result;
- net_nfc_request_close_internal_se_t request = { 0, };
-
- if (handle == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- request.length = sizeof(net_nfc_request_close_internal_se_t);
- request.request_type = NET_NFC_MESSAGE_CLOSE_INTERNAL_SE;
- request.handle = (net_nfc_target_handle_s *)handle;
-
- result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL);
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_apdu(net_nfc_target_handle_h handle, data_h apdu, void *trans_param)
-{
- net_nfc_error_e ret;
- net_nfc_request_send_apdu_t *request = NULL;
- uint32_t length = 0;
- data_s *apdu_data = (data_s *)apdu;
-
- if (handle == NULL || apdu_data == NULL || apdu_data->buffer == NULL || apdu_data->length == 0)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- length = sizeof(net_nfc_request_send_apdu_t) + apdu_data->length;
-
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_SEND_APDU_SE;
- request->handle = (net_nfc_target_handle_s *)handle;
- request->trans_param = trans_param;
-
- request->data.length = apdu_data->length;
- memcpy(&request->data.buffer, apdu_data->buffer, request->data.length);
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
-
- _net_nfc_util_free_mem(request);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_apdu_sync(net_nfc_target_handle_h handle, data_h apdu, data_h *response)
-{
- net_nfc_request_send_apdu_t *request = NULL;
- data_s *apdu_data = (data_s *)apdu;
- net_nfc_error_e result;
- uint32_t length;
- data_h resp = NULL;
-
- if (handle == NULL || apdu_data == NULL || apdu_data->buffer == NULL || apdu_data->length == 0)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- length = sizeof(net_nfc_request_send_apdu_t) + apdu_data->length;
-
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_SEND_APDU_SE;
- request->handle = (net_nfc_target_handle_s *)handle;
- request->user_param = (uint32_t)&resp;
-
- request->data.length = apdu_data->length;
- memcpy(&request->data.buffer, apdu_data->buffer, request->data.length);
-
- result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)request, NULL);
- if (result == NET_NFC_OK) {
- if (resp != NULL) {
- *response = resp;
- } else {
- DEBUG_ERR_MSG("NULL response returned");
- result = NET_NFC_OPERATION_FAIL;
- }
- } else {
- DEBUG_ERR_MSG("net_nfc_client_send_request_sync failed [%d]", result);
- }
-
- _net_nfc_util_free_mem(request);
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_atr(net_nfc_target_handle_h handle, void *trans_param)
-{
- net_nfc_error_e ret;
- net_nfc_request_get_atr_t request = { 0, };
-
- if (handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- request.length = sizeof(net_nfc_request_get_atr_t);
- request.request_type = NET_NFC_MESSAGE_GET_ATR_SE;
- request.handle = (net_nfc_target_handle_s *)handle;
- request.user_param = (uint32_t)trans_param;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_atr_sync(net_nfc_target_handle_h handle, data_h *atr)
-{
- net_nfc_request_get_atr_t request = { 0, };
- data_h response = NULL;
- net_nfc_error_e result;
-
- if (handle == NULL) {
- return NET_NFC_NULL_PARAMETER;
- }
-
- request.length = sizeof(net_nfc_request_get_atr_t);
- request.request_type = NET_NFC_MESSAGE_GET_ATR_SE;
- request.handle = (net_nfc_target_handle_s *)handle;
- request.user_param = (uint32_t)&response;
-
- result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL);
- if (result == NET_NFC_OK) {
- if (response != NULL) {
- *atr = response;
- } else {
- result = NET_NFC_OPERATION_FAIL;
- }
- }
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/un.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/epoll.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <glib-object.h>
-
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_client_ipc_private.h"
-#include "net_nfc_client_dispatcher_private.h"
-
-/* static variable */
-static pid_t g_client_pid;
-static int g_client_sock_fd = -1;
-static pthread_mutex_t g_client_ipc_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t g_client_ipc_cond = PTHREAD_COND_INITIALIZER;
-static pthread_mutex_t cb_lock = PTHREAD_MUTEX_INITIALIZER;
-static net_nfc_response_cb client_cb = NULL;
-static net_nfc_error_e sync_result;
-
-#ifdef G_MAIN_LOOP
-static GIOChannel *g_client_channel = NULL;
-static uint32_t g_client_src_id = 0;
-#else
-#ifdef USE_IPC_EPOLL
-#define EPOLL_SIZE 128
-static int g_client_poll_fd = -1;
-static struct epoll_event g_client_poll_event = { 0, };
-#else
-static fd_set fdset_read;
-#endif
-static pthread_t g_poll_thread = (pthread_t)0;
-#endif
-
-/* static function */
-static net_nfc_response_msg_t *net_nfc_client_read_response_msg(net_nfc_error_e *result);
-#ifdef G_MAIN_LOOP
-gboolean net_nfc_client_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data);
-#else
-static bool net_nfc_client_ipc_polling(net_nfc_error_e *result);
-static void *net_nfc_client_ipc_thread(void *data);
-#endif
-
-/////////////////////
-
-inline void net_nfc_client_ipc_lock()
-{
- pthread_mutex_lock(&g_client_ipc_mutex);
-}
-
-inline void net_nfc_client_ipc_unlock()
-{
- pthread_mutex_unlock(&g_client_ipc_mutex);
-}
-
-static void net_nfc_client_prepare_sync_call(net_nfc_request_msg_t *msg)
-{
- net_nfc_client_ipc_lock();
-
- NET_NFC_FLAGS_SET_SYNC_CALL(msg->flags);
-}
-
-static net_nfc_error_e net_nfc_client_wait_sync_call(int timeout)
-{
- net_nfc_error_e result = NET_NFC_OPERATION_FAIL;
- struct timeval now;
- struct timespec ts;
-
- gettimeofday(&now, NULL);
- ts.tv_sec = now.tv_sec + timeout;
- ts.tv_nsec = now.tv_usec * 1000;
-
- if (pthread_cond_timedwait(&g_client_ipc_cond, &g_client_ipc_mutex,
- &ts) == 0)
- {
- result = sync_result;
- }
-
- return result;
-}
-
-static void net_nfc_client_post_sync_call()
-{
- net_nfc_client_ipc_unlock();
-}
-
-static void net_nfc_client_recv_sync_call()
-{
- net_nfc_client_ipc_lock();
-}
-
-static void net_nfc_client_notify_sync_call(net_nfc_error_e result)
-{
- sync_result = result;
-
- pthread_cond_signal(&g_client_ipc_cond);
- net_nfc_client_ipc_unlock();
-}
-
-bool net_nfc_client_is_connected()
-{
-#ifdef G_MAIN_LOOP
- if (g_client_sock_fd != -1 && g_client_channel != NULL && g_client_src_id != 0)
-#else
-#ifdef USE_IPC_EPOLL
- if (g_client_sock_fd != -1 && g_client_poll_fd != -1 && g_poll_thread != (pthread_t)NULL)
-#else
- if (g_client_sock_fd != -1 && g_poll_thread != (pthread_t)NULL)
-#endif
-#endif
- {
- return true;
- }
- else
- {
- return false;
- }
-}
-
-static net_nfc_error_e _finalize_client_socket()
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- DEBUG_CLIENT_MSG("finalize client socket");
-
- net_nfc_client_ipc_lock();
-
- if (g_client_sock_fd != -1)
- {
-#ifdef G_MAIN_LOOP
- g_io_channel_unref(g_client_channel);
- g_client_channel = NULL;
-
- g_source_remove(g_client_src_id);
- g_client_src_id = 0;
-#else
-#if 0
- if (g_poll_thread != (pthread_t)NULL)
- {
-#ifdef NET_NFC_USE_SIGTERM
- /* This is dangerous because of the lock inside of the thread it creates dead lock!
- * it may damage the application data or lockup, sigterm can be recieved while the application codes is executed in callback function
- */
- pthread_kill(g_poll_thread, SIGTERM);
-#else
- DEBUG_CLIENT_MSG("join epoll_thread start");
- pthread_join(g_poll_thread, NULL);
- DEBUG_CLIENT_MSG("join epoll_thread end");
-#endif
- }
- g_poll_thread = (pthread_t)NULL;
-#endif
-#ifdef USE_IPC_EPOLL
- if (g_client_poll_fd != -1)
- {
- struct epoll_event ev;
-
- ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP | EPOLLERR;
- ev.data.fd = g_client_sock_fd;
-
- int ret = epoll_ctl(g_client_poll_fd, EPOLL_CTL_DEL, g_client_sock_fd, &ev);
-
- ret = close(g_client_poll_fd);
- g_client_poll_fd = -1;
- DEBUG_CLIENT_MSG("epoll close, %d", ret);
- }
-#else
- FD_CLR(g_client_sock_fd, &fdset_read);
-#endif
-#endif // #ifdef G_MAIN_LOOP
- close(g_client_sock_fd);
- g_client_sock_fd = -1;
- DEBUG_CLIENT_MSG("close socket");
- }
-
- net_nfc_client_ipc_unlock();
-
- return result;
-}
-
-net_nfc_error_e net_nfc_client_socket_initialize()
-{
- int ret;
- net_nfc_error_e result = NET_NFC_OK;
-
- if (net_nfc_client_is_connected() == true)
- {
- DEBUG_CLIENT_MSG("client is already initialized");
- return NET_NFC_ALREADY_INITIALIZED;
- }
-
- g_client_pid = getpid();
-
- pthread_mutexattr_t attr;
-
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
- pthread_mutex_init(&cb_lock, &attr);
-
-#ifdef USE_UNIX_DOMAIN
- struct sockaddr_un saddrun_rv;
- socklen_t len_saddr = 0;
-
- memset(&saddrun_rv, 0, sizeof(struct sockaddr_un));
-
- net_nfc_client_ipc_lock();
-
- g_client_sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (g_client_sock_fd == -1)
- {
- DEBUG_ERR_MSG("get socket is failed");
- net_nfc_client_ipc_unlock();
- return NET_NFC_IPC_FAIL;
- }
-
- DEBUG_CLIENT_MSG("socket is created");
-
- net_nfc_util_set_non_block_socket(g_client_sock_fd);
-
- saddrun_rv.sun_family = AF_UNIX;
- strncpy(saddrun_rv.sun_path, NET_NFC_SERVER_DOMAIN, sizeof(saddrun_rv.sun_path) - 1);
-
- len_saddr = sizeof(saddrun_rv.sun_family) + strlen(NET_NFC_SERVER_DOMAIN);
-
- if (connect(g_client_sock_fd, (struct sockaddr *)&saddrun_rv, len_saddr) < 0)
- {
- DEBUG_ERR_MSG("error is occured");
- result = NET_NFC_IPC_FAIL;
- goto ERROR;
- }
-#else
- struct sockaddr_in serv_addr;
- memset(&serv_addr, 0x00, sizeof(struct sockaddr_in));
-
- g_client_sock_fd = socket(PF_INET, SOCK_STREAM, 0);
-
- if (g_client_sock_fd == -1)
- {
- DEBUG_ERR_MSG("get socket is failed ");
- net_nfc_client_ipc_unlock();
- return NET_NFC_IPC_FAIL;
- }
-
- DEBUG_CLIENT_MSG("socket is created");
-
- net_nfc_util_set_non_block_socket(g_client_sock_fd);
-
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_port = htons(NET_NFC_SERVER_PORT);
-
- if ((connect(g_client_sock_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0)
- {
- DEBUG_ERR_MSG("error is occured");
- result = NET_NFC_IPC_FAIL;
- goto ERROR;
- }
-
-#endif
-
-#ifdef G_MAIN_LOOP
-
- GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN);
-
- if ((g_client_channel = g_io_channel_unix_new(g_client_sock_fd)) != NULL)
- {
- if ((g_client_src_id = g_io_add_watch(g_client_channel, condition, net_nfc_client_ipc_callback_func, NULL)) < 1)
- {
- DEBUG_ERR_MSG(" g_io_add_watch is failed ");
- result = NET_NFC_IPC_FAIL;
- goto ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG(" g_io_channel_unix_new is failed ");
- result = NET_NFC_IPC_FAIL;
- goto ERROR;
- }
-
- DEBUG_CLIENT_MSG("socket and g io channel is binded");
-
-#else
-
-#ifdef USE_IPC_EPOLL
- if ((g_client_poll_fd = epoll_create1(EPOLL_CLOEXEC)) == -1)
- {
- DEBUG_ERR_MSG("error is occured");
- result = NET_NFC_IPC_FAIL;
- goto ERROR;
- }
-
- memset(&g_client_poll_event, 0, sizeof(g_client_poll_event));
-
- struct epoll_event ev;
-
- ev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR;
- ev.data.fd = g_client_sock_fd;
-
- ret = epoll_ctl(g_client_poll_fd, EPOLL_CTL_ADD, g_client_sock_fd, &ev);
-#else
- FD_ZERO(&fdset_read);
- FD_SET(g_client_sock_fd, &fdset_read);
-#endif
-
- /* create polling thread and go */
- pthread_attr_t thread_attr;
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
-
- pthread_cond_t pcond = PTHREAD_COND_INITIALIZER;
-
- if (pthread_create(&g_poll_thread, NULL, net_nfc_client_ipc_thread, &pcond) != 0)
- {
- DEBUG_ERR_MSG("error is occured");
- pthread_attr_destroy(&thread_attr);
- result = NET_NFC_THREAD_CREATE_FAIL;
- goto ERROR;
- }
-
- usleep(0);
-
-#ifdef NET_NFC_USE_SIGTERM
- pthread_cond_wait(&pcond, &g_client_ipc_mutex);
-#endif
-
- DEBUG_CLIENT_MSG("start ipc thread = [%x]", (uint32_t)g_poll_thread);
-
- //////////////////////////////////
-
- pthread_attr_destroy(&thread_attr);
-
-#endif // #ifdef G_MAIN_LOOP
- net_nfc_client_ipc_unlock();
-
- return NET_NFC_OK;
-
-ERROR :
- DEBUG_ERR_MSG("error while initializing client ipc");
-
- net_nfc_client_ipc_unlock();
-
- _finalize_client_socket();
-
- return result;
-}
-
-#ifdef NET_NFC_USE_SIGTERM
-static void thread_sig_handler(int signo)
-{
- /* do nothing */
-}
-#endif
-
-#ifndef G_MAIN_LOOP
-static void *net_nfc_client_ipc_thread(void *data)
-{
- DEBUG_CLIENT_MSG("net_nfc_client_ipc_thread is started = [0x%lx]", pthread_self());
-
-#ifdef NET_NFC_USE_SIGTERM
-
- struct sigaction act;
- act.sa_handler = thread_sig_handler;
- sigaction(SIGTERM, &act, NULL);
-
- sigset_t newmask;
- sigemptyset(&newmask);
- sigaddset(&newmask, SIGTERM);
- pthread_sigmask(SIG_UNBLOCK, &newmask, NULL);
- DEBUG_CLIENT_MSG("sighandler is registered");
-
-#endif
-
-#ifdef NET_NFC_USE_SIGTERM
- net_nfc_client_ipc_lock();
- pthread_cond_signal((pthread_cond_t *)data);
- net_nfc_client_ipc_unlock();
-#endif
-
- bool condition = true;
-
- while (condition == true)
- {
- net_nfc_error_e result = 0;
-
- if (net_nfc_client_ipc_polling(&result) != true)
- {
- switch (result)
- {
- case NET_NFC_OPERATION_FAIL :
- DEBUG_CLIENT_MSG("shutdown request from server, stop ipc polling thread");
- _finalize_client_socket();
- condition = false;
- break;
-
- case NET_NFC_IPC_FAIL :
- DEBUG_ERR_MSG("abnormal socket close.");
- _finalize_client_socket();
- condition = false;
- break;
-
- default :
- DEBUG_ERR_MSG("???");
- break;
- }
- }
- else
- {
- net_nfc_response_msg_t *msg = NULL;
-
- DEBUG_CLIENT_MSG("message is coming from server to client");
-
- msg = net_nfc_client_read_response_msg(&result);
-
- if (msg != NULL && msg->detail_message != NULL)
- {
- /* TODO : need to remove */
- net_nfc_response_msg_t *temp = (net_nfc_response_msg_t *)(msg->detail_message);
-;
- if (NET_NFC_FLAGS_IS_SYNC_CALL(temp->flags))
- {
- net_nfc_error_e result;
-
- net_nfc_client_recv_sync_call();
-
- /* call a callback in IPC thread */
- result = net_nfc_client_dispatch_sync_response(msg);
-
- /* unset sync call flag */
- net_nfc_client_notify_sync_call(result);
- }
- else
- {
- pthread_mutex_lock(&cb_lock);
-#ifdef USE_GLIB_MAIN_LOOP
- net_nfc_client_call_dispatcher_in_g_main_loop(client_cb, msg);
-#elif USE_ECORE_MAIN_LOOP
- net_nfc_client_call_dispatcher_in_ecore_main_loop(client_cb, msg);
-#else
- net_nfc_client_call_dispatcher_in_current_context(client_cb, msg);
-#endif
- pthread_mutex_unlock(&cb_lock);
- }
- }
- else
- {
- /* if client is waiting for unlock signal, then unlock it.
- * and send error message
- * or make error response message and pass to client callback
- */
- if (net_nfc_client_is_connected() == false)
- {
- condition = false;
- }
- DEBUG_ERR_MSG("cannot read response msg");
- }
- }
- }
-
- DEBUG_CLIENT_MSG("net_nfc_client_ipc_thread is terminated");
-
- return (void *)NULL;
-}
-#endif
-
-#ifdef G_MAIN_LOOP
-gboolean net_nfc_client_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data)
-{
- DEBUG_CLIENT_MSG("event is detected on client socket");
-
- if(G_IO_IN & condition)
- {
-
- int client_sock_fd = 0;
-
- if(channel == g_client_channel)
- {
-
- DEBUG_CLIENT_MSG("message from server to client socket");
-
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_response_msg_t *msg = net_nfc_client_read_response_msg(&result);
-
- if(msg != NULL)
- {
-
- net_nfc_client_call_dispatcher_in_current_context(client_cb, msg);
- }
- else
- {
- DEBUG_CLIENT_MSG("can not read response msg or callback is NULL");
- }
-
- }
- else
- {
- DEBUG_CLIENT_MSG("unknown channel ");
- return FALSE;
- }
- }
- else
- {
-
- DEBUG_CLIENT_MSG("IO ERROR. socket is closed ");
-
- /* clean up client context */
- net_nfc_client_socket_finalize();
-
- return FALSE;
- }
-
- return TRUE;
-}
-#else
-bool net_nfc_client_ipc_polling(net_nfc_error_e *result)
-{
- int num_of_sockets = 0;
-
- if (result == NULL)
- {
- return false;
- }
-
- *result = NET_NFC_OK;
-
-#ifdef USE_IPC_EPOLL
- DEBUG_CLIENT_MSG("wait event from epoll");
-
- if (g_client_poll_fd == -1 || g_client_sock_fd == -1)
- {
- DEBUG_ERR_MSG("client is deinitialized. ");
- *result = NET_NFC_IPC_FAIL;
- return false;
- }
-
- /* 0.5sec */
-#ifndef USE_EPOLL_TIMEOUT
- while ((num_of_sockets = epoll_wait(g_client_poll_fd, &g_client_poll_event, 1, 300)) == 0)
- {
- if (g_client_poll_fd == -1)
- {
- DEBUG_CLIENT_MSG("client ipc thread is terminated");
- return false;
- }
- }
-#else
- num_of_sockets = epoll_wait(g_client_poll_fd, &g_client_poll_event, 1, -1);
-#endif
- if (num_of_sockets == 1)
- {
- if (g_client_poll_event.events & EPOLLRDHUP)
- {
- DEBUG_CLIENT_MSG("EPOLLRDHUP");
- *result = NET_NFC_OPERATION_FAIL;
- return false;
- }
- else if (g_client_poll_event.events & EPOLLHUP)
- {
- DEBUG_CLIENT_MSG("EPOLLHUP");
- *result = NET_NFC_IPC_FAIL;
- return false;
- }
- else if (g_client_poll_event.events & EPOLLERR)
- {
- DEBUG_CLIENT_MSG("EPOLLERR");
- *result = NET_NFC_IPC_FAIL;
- return false;
- }
- else if (g_client_poll_event.events & EPOLLIN)
- {
- if (g_client_poll_event.data.fd == g_client_sock_fd)
- {
- return true;
- }
- else
- {
- DEBUG_ERR_MSG("unexpected socket connection");
- return false;
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("epoll_wait returns error");
- return false;
- }
-#else
- DEBUG_CLIENT_MSG("wait event from select");
-
- int temp = select(g_client_sock_fd + 1, &fdset_read, NULL, NULL, NULL);
-
- if(temp > 0)
- {
- if(FD_ISSET(g_client_sock_fd, &fdset_read) == true)
- {
- int val = 0;
- int size = 0;
-
- if(getsockopt(g_client_sock_fd, SOL_SOCKET, SO_ERROR, &val, &size) == 0)
- {
- if(val != 0)
- {
- DEBUG_CLIENT_MSG("socket is on error");
- return false;
- }
- else
- {
- DEBUG_CLIENT_MSG("socket is readable");
- return true;
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("unknown error");
- *result = NET_NFC_IPC_FAIL;
- return false;
- }
- }
-#endif
-
- DEBUG_CLIENT_MSG("polling error");
- *result = NET_NFC_IPC_FAIL;
- return false;
-}
-#endif
-
-void net_nfc_client_socket_finalize()
-{
- net_nfc_client_ipc_lock();
-
- if (g_client_sock_fd != -1)
- {
- DEBUG_CLIENT_MSG("shutdown socket, and wait EPOLLRDHUP");
- shutdown(g_client_sock_fd, SHUT_WR);
- }
-
- net_nfc_client_ipc_unlock();
-}
-
-int __net_nfc_client_read_util(void **detail, size_t size)
-{
- int length;
- static uint8_t flushing[128];
-
- if (recv(g_client_sock_fd, &length, sizeof(length), 0) != sizeof(length))
- {
- return 0;
- }
-
- *detail = NULL;
- _net_nfc_util_alloc_mem(*detail, size);
-
- /* if the allocation is failed, this codes flush out all the buffered data */
- if (*detail == NULL)
- {
- size_t read_size;
- int readbytes = size;
- while (readbytes > 0)
- {
- read_size = readbytes > 128 ? 128 : readbytes;
- if (recv(g_client_sock_fd, flushing, read_size, 0) <= 0)
- {
- return 0;
- }
- readbytes -= read_size;
- }
- return 0;
- }
- /* read */
- if (recv(g_client_sock_fd, *detail, size, 0) <= 0)
- {
- _net_nfc_util_free_mem(*detail);
- return 0;
- }
- return 1;
-}
-
-net_nfc_response_msg_t *net_nfc_client_read_response_msg(net_nfc_error_e *result)
-{
- net_nfc_response_msg_t *resp_msg = NULL;
-
- _net_nfc_util_alloc_mem(resp_msg, sizeof(net_nfc_response_msg_t));
- if (resp_msg == NULL)
- {
- DEBUG_ERR_MSG("malloc fail");
- *result = NET_NFC_ALLOC_FAIL;
- return NULL;
- }
-
- if (recv(g_client_sock_fd, (void *)&(resp_msg->response_type), sizeof(int), 0) != sizeof(int))
- {
- DEBUG_ERR_MSG("reading message is failed");
- _net_nfc_util_free_mem(resp_msg);
-
- return NULL;
- }
-
-// DEBUG_MSG("<<<<< FROM SERVER <<<<< (msg [%d], length [%d])", resp_msg->response_type, length);
- DEBUG_MSG("[%d] <<<<<<<<<<<<<<< (msg [%d])", g_client_pid, resp_msg->response_type);
-
- switch (resp_msg->response_type)
- {
- case NET_NFC_MESSAGE_SET_SE :
- {
- net_nfc_response_set_se_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_set_se_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_GET_SE :
- {
- net_nfc_response_get_se_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_se_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_SE_TYPE_CHANGED :
- {
- net_nfc_response_notify_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_notify_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
- {
- net_nfc_response_open_internal_se_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_open_internal_se_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- DEBUG_CLIENT_MSG("handle = [0x%p]", resp_detail->handle);
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
- {
- net_nfc_response_close_internal_se_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_close_internal_se_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_SEND_APDU_SE :
- {
-
- net_nfc_response_send_apdu_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_send_apdu_t));
- if (res == 1)
- {
- if (resp_detail->data.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length);
- if (res == 2)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->data.buffer = NULL;
- }
- }
- if (res == 0)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_TAG_DISCOVERED :
- {
- net_nfc_response_tag_discovered_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_tag_discovered_t));
- if (res == 1)
- {
- if (resp_detail->target_info_values.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length);
- if (res == 2)
- {
- if (resp_detail->raw_data.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->raw_data.buffer), resp_detail->raw_data.length);
- if (res == 3)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->raw_data.buffer = NULL;
- }
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->target_info_values.buffer = NULL;
- }
- }
- if (res == 0)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO :
- {
- net_nfc_response_get_current_tag_info_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_current_tag_info_t));
- if (res == 1)
- {
- if (resp_detail->target_info_values.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length);
- if (res == 2)
- {
- if (resp_detail->raw_data.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->raw_data.buffer), resp_detail->raw_data.length);
- if (res == 3)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->raw_data.buffer = NULL;
- }
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->target_info_values.buffer = NULL;
- }
- }
- if (res == 0)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_SE_START_TRANSACTION :
- case NET_NFC_MESSAGE_SE_END_TRANSACTION :
- case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION :
- case NET_NFC_MESSAGE_SE_CONNECTIVITY :
- case NET_NFC_MESSAGE_SE_FIELD_ON :
- case NET_NFC_MESSAGE_SE_FIELD_OFF :
- {
- net_nfc_response_se_event_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_se_event_t));
- if (res == 1)
- {
- if (resp_detail->aid.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->aid.buffer), resp_detail->aid.length);
- if (res == 2)
- {
- if (resp_detail->param.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->param.buffer), resp_detail->param.length);
- if (res == 3)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->param.buffer = NULL;
- }
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->aid.buffer = NULL;
- }
- }
- if (res == 0)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_TRANSCEIVE :
- {
- net_nfc_response_transceive_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_transceive_t));
- if (res == 1)
- {
- if (resp_detail->data.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length);
- if (res == 2)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->data.buffer = NULL;
- }
- }
- if (res == 0)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF :
- {
-
- net_nfc_response_read_ndef_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_read_ndef_t));
- if (res == 1)
- {
- if (resp_detail->data.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length);
- if (res == 2)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->data.buffer = NULL;
- }
- }
- if (res == 0)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_WRITE_NDEF :
- {
- net_nfc_response_write_ndef_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_write_ndef_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_SIM_TEST :
- {
- net_nfc_response_test_t *resp_detail = NULL;
- int res = 0;
-
- DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_SIM_TEST");
-
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_PRBS_TEST :
- {
- net_nfc_response_test_t *resp_detail = NULL;
- int res = 0;
-
- DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_PRBS_TEST");
-
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_SET_EEDATA :
- {
- net_nfc_response_test_t *resp_detail = NULL;
- int res = 0;
-
- DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_SET_EEDATA");
-
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION :
- {
- net_nfc_response_firmware_version_t *resp_detail = NULL;
-
- DEBUG_CLIENT_MSG("message from server NET_NFC_MESSAGE_GET_FIRMWARE_VERSION");
-
- if (__net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_firmware_version_t)) > 0)
- {
- if (__net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length) > 0)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_msg);
- _net_nfc_util_free_mem(resp_detail);
- return NULL;
- }
- }
- else
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_NOTIFY :
- {
- net_nfc_response_notify_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_notify_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
- case NET_NFC_MESSAGE_TAG_DETACHED :
- {
- net_nfc_response_target_detached_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_target_detached_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_FORMAT_NDEF :
- {
-
- net_nfc_response_format_ndef_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_format_ndef_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
-
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_DISCOVERED :
- {
- net_nfc_response_llcp_discovered_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_discovered_t));
- if (res == 1)
- {
- if (resp_detail->target_info_values.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->target_info_values.buffer), resp_detail->target_info_values.length);
- if (res == 2)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->target_info_values.buffer = NULL;
- }
- }
- if (res == 0)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_DETACHED :
- {
- net_nfc_response_llcp_detached_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_detached_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_LISTEN :
- {
- net_nfc_response_listen_socket_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_listen_socket_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
-
- }
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT :
- {
- net_nfc_response_connect_socket_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connect_socket_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
-
- }
- break;
- case NET_NFC_MESSAGE_LLCP_CONNECT_SAP :
- {
- net_nfc_response_connect_sap_socket_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connect_sap_socket_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
-
- }
- break;
- case NET_NFC_MESSAGE_LLCP_SEND :
- {
- net_nfc_response_send_socket_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_send_socket_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE :
- {
- net_nfc_response_receive_socket_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_receive_socket_t));
- if (res == 1)
- {
-
- if (resp_detail->data.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length);
- }
- if (res == 2)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->data.buffer = NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_RECEIVE :
- {
- net_nfc_response_p2p_receive_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_receive_t));
- if (res == 1)
- {
-
- if (resp_detail->data.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length);
- }
- if (res == 2)
- {
- resp_msg->detail_message = resp_detail;
- }
- else
- {
- _net_nfc_util_free_mem(resp_detail);
- res--;
- }
- }
- else
- {
- resp_msg->detail_message = resp_detail;
- resp_detail->data.buffer = NULL;
- }
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE :
- {
- net_nfc_response_close_socket_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_close_socket_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
- case NET_NFC_MESSAGE_LLCP_DISCONNECT :
- {
- net_nfc_response_disconnect_socket_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_disconnect_socket_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONFIG :
- {
- net_nfc_response_config_llcp_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_config_llcp_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_ERROR :
- {
- net_nfc_response_llcp_socket_error_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_llcp_socket_error_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_ACCEPTED :
- {
- net_nfc_response_incomming_llcp_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_incomming_llcp_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_DISCOVERED :
- {
- net_nfc_response_p2p_discovered_t *resp_detail = NULL;
- int res = 0;
-
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_discovered_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_SEND :
- {
- net_nfc_response_p2p_send_t *resp_detail = NULL;
- int res = 0;
-
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_p2p_send_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
- {
- net_nfc_response_connection_handover_t *resp_detail = NULL;
- int res = 0;
-
- DEBUG_CLIENT_MSG("NET_NFC_MESSAGE_CONNECTION_HANDOVER");
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_connection_handover_t));
-
- if (res == 1)
- {
- if (resp_detail->data.length > 0)
- {
- res += __net_nfc_client_read_util((void **)&(resp_detail->data.buffer), resp_detail->data.length);
- if (res < 2)
- {
- DEBUG_ERR_MSG("__net_nfc_client_read_util failed. res [%d]", res);
- _net_nfc_util_free_mem(resp_detail);
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("__net_nfc_client_read_util failed. res [%d]", res);
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
-
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_IS_TAG_CONNECTED :
- {
- net_nfc_response_is_tag_connected_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_is_tag_connected_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
- }
- break;
-
- case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE :
- {
- net_nfc_response_get_current_target_handle_t *resp_detail = NULL;
- int res = 0;
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_get_current_target_handle_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
-
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_INIT :
- {
- net_nfc_response_test_t *resp_detail = NULL;
- int res = 0;
-
- DEBUG_CLIENT_MSG("Client Receive the NET_NFC_MESSAGE_SERVICE_INIT");
-
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
-
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_DEINIT :
- {
- net_nfc_response_test_t *resp_detail = NULL;
- int res = 0;
-
- DEBUG_CLIENT_MSG("Client Receive the NET_NFC_MESSAGE_SERVICE_DEINIT");
-
- res = __net_nfc_client_read_util((void **)&resp_detail, sizeof(net_nfc_response_test_t));
- if (res != 1)
- {
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
- resp_msg->detail_message = resp_detail;
-
- }
- break;
-
- default :
- {
- DEBUG_CLIENT_MSG("Currently NOT supported RESP TYPE = [%d]", resp_msg->response_type);
- _net_nfc_util_free_mem(resp_msg);
- return NULL;
- }
-
- }
-
- return resp_msg;
-}
-
-bool __net_nfc_client_send_msg(void *message, int length)
-{
- bool result = (send(g_client_sock_fd, (void *)message, length, MSG_NOSIGNAL) > 0);
-
- if (result == false)
- {
- uint8_t buf[1024] = { 0x00, };
- DEBUG_ERR_MSG("send failed : %s", strerror_r(errno, (char *)buf, sizeof(buf)));
- }
-
- return result;
-}
-
-static char *cookies = NULL;
-static int cookies_size = 0;
-
-void _net_nfc_client_set_cookies(const char *cookie, size_t size)
-{
- if (cookie != NULL && size > 0)
- {
- _net_nfc_util_alloc_mem(cookies, size);
-
- memcpy(cookies, cookie, size);
- cookies_size = size;
- }
-}
-
-void _net_nfc_client_free_cookies(void)
-{
- _net_nfc_util_free_mem(cookies);
- cookies_size = 0;
-}
-
-static net_nfc_error_e _send_request(net_nfc_request_msg_t *msg, va_list list)
-{
- uint8_t *send_buffer = NULL;
- int total_size = 0;
- int written_size = 0;
-
- /* calc message length */
-#ifdef SECURITY_SERVER
- total_size += (sizeof(cookies_size) + cookies_size);
-#endif
- total_size += msg->length;
- total_size += net_nfc_util_get_va_list_length(list);
-
- _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size));
- if (send_buffer == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
-
- /* fill message */
- /* - total length */
- memcpy(send_buffer + written_size, &total_size, sizeof(total_size));
- written_size += sizeof(total_size);
-
-#ifdef SECURITY_SERVER
- /* -- security server cookie */
- memcpy(send_buffer + written_size, &cookies_size, sizeof(cookies_size));
- written_size += sizeof(cookies_size);
-
- memcpy(send_buffer + written_size, cookies, cookies_size);
- written_size += cookies_size;
-#endif
-
- /* -- request message struct */
- memcpy(send_buffer + written_size, msg, msg->length);
- written_size += msg->length;
-
- /* -- varient arguemts */
- written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list);
-
- bool msg_result = __net_nfc_client_send_msg((void *)send_buffer, total_size + sizeof(total_size));
-
- _net_nfc_util_free_mem(send_buffer);
- sleep(0);
-
- if (msg_result)
- {
- DEBUG_MSG("[%d] >>>>>>>>>>>>>>> (msg [%d], length [%d])", g_client_pid, msg->request_type, total_size);
- return NET_NFC_OK;
- }
- else
- {
- return NET_NFC_IPC_FAIL;
- }
-}
-
-net_nfc_error_e net_nfc_client_send_request(net_nfc_request_msg_t *msg, ...)
-{
- va_list list;
- net_nfc_error_e result = NET_NFC_OK;
-
- va_start(list, msg);
-
- net_nfc_client_ipc_lock();
-
- result = _send_request(msg, list);
-
- net_nfc_client_ipc_unlock();
-
- va_end(list);
-
- return result;
-}
-
-net_nfc_error_e net_nfc_client_send_request_sync(net_nfc_request_msg_t *msg, ...)
-{
- va_list list;
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_client_prepare_sync_call(msg);
-
- va_start(list, msg);
-
- result = _send_request(msg, list);
-
- va_end(list);
-
- if (result == NET_NFC_OK)
- {
- result = net_nfc_client_wait_sync_call(3);
- }
- net_nfc_client_post_sync_call();
-
- return result;
-}
-
-net_nfc_error_e _net_nfc_client_register_cb(net_nfc_response_cb cb)
-{
- if (cb == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- pthread_mutex_lock(&cb_lock);
- client_cb = cb;
- pthread_mutex_unlock(&cb_lock);
-
- return NET_NFC_OK;
-}
-
-net_nfc_error_e _net_nfc_client_unregister_cb(void)
-{
- if (client_cb == NULL)
- {
- return NET_NFC_NOT_REGISTERED;
- }
-
- pthread_mutex_lock(&cb_lock);
- client_cb = NULL;
- pthread_mutex_unlock(&cb_lock);
-
- return NET_NFC_OK;
-}
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <glib.h>
-#include <pthread.h>
-
-#include "net_nfc_llcp.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_client_ipc_private.h"
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_llcp.h"
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
#endif
-GList * socket_list = NULL;
+typedef struct _LlcpFuncData LlcpFuncData;
-/*
- Concept of the llcp_lock
- 1. this lock protects only between client thread (these are calling llcp apis) and callback thread queue (=dispatcher thread)
- 2. dispatcher thread is always serial it does not have to protect itself.
- 3. all internal function for example __free_socket_info, __socket_equal_to are used only inside of this file
- (there is no way to access from client api) thread safe.
- 4. if the internal function calles from other thread (or changed to public) then you should consider use lock
-*/
-static pthread_mutex_t llcp_lock = PTHREAD_MUTEX_INITIALIZER;
-
-/* to share client info */
-unsigned int socket_handle = 0; /* to generate client socket handle */
-static net_nfc_target_handle_s * current_target = NULL;
-
-static net_nfc_llcp_config_info_s local_config = { 128, 1, 10, 0 };
-static net_nfc_llcp_config_info_s remote_config = { 128, 1, 10, 0 };
-
-/* =============================================================== */
-/* Socket info util */
-
-static void __free_socket_info(net_nfc_llcp_internal_socket_s * data)
+struct _LlcpFuncData
{
- net_nfc_llcp_internal_socket_s * socket_info = (net_nfc_llcp_internal_socket_s *)data;
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusLlcp *llcp_proxy = NULL;
+static net_nfc_llcp_config_info_s llcp_config = { 128, 0, 0, 1 };
+static net_nfc_target_handle_s *llcp_handle = NULL;
+static GList *socket_data_list = NULL;
+static guint socket_handle = 0;
+
+
+void llcp_socket_data_append(net_nfc_llcp_internal_socket_s *socket_data);
+
+void llcp_socket_data_remove(net_nfc_llcp_internal_socket_s *socket_data);
+
+net_nfc_llcp_internal_socket_s *llcp_socket_data_find
+ (net_nfc_llcp_socket_t socket);
+
+/* aysnc callback */
+static void llcp_call_config(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_listen(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_connect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_connect_sap(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
- if (socket_info == NULL)
+static void llcp_call_send(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_send_to(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_receive(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_receive_from(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_close(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void llcp_call_disconnect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+/* signal callback */
+static void llcp_error(NetNfcGDbusLlcp *object,
+ guint arg_handle,
+ guint client_socket,
+ guint oal_socket,
+ gint error,
+ gpointer user_data);
+
+
+void llcp_socket_data_append(net_nfc_llcp_internal_socket_s *socket_data)
+{
+ if (socket_data_list == NULL)
return;
- _net_nfc_util_free_mem(socket_info->service_name);
- _net_nfc_util_free_mem(socket_info);
+
+ if (socket_data)
+ {
+ socket_data_list = g_list_append(socket_data_list,
+ socket_data);
+ }
}
-static int __socket_equal_to(gconstpointer key1, gconstpointer key2)
+void llcp_socket_data_remove(net_nfc_llcp_internal_socket_s *socket_data)
{
- net_nfc_llcp_internal_socket_s * arg1 = (net_nfc_llcp_internal_socket_s *)key1;
- net_nfc_llcp_internal_socket_s * arg2 = (net_nfc_llcp_internal_socket_s *)key2;
+ if (socket_data_list == NULL)
+ return;
- if (arg1->client_socket < arg2->client_socket)
+ if (socket_data)
{
- return -1;
+ socket_data_list = g_list_remove(socket_data_list,
+ socket_data);
+
+ g_free(socket_data->service_name);
+ g_free(socket_data);
}
- else if (arg1->client_socket > arg2->client_socket)
+}
+
+net_nfc_llcp_internal_socket_s *llcp_socket_data_find
+ (net_nfc_llcp_socket_t socket)
+{
+ GList *pos;
+
+ if (socket_data_list == NULL)
+ return NULL;
+
+
+ for (pos = g_list_first(socket_data_list); pos ; pos = pos->data)
{
- return 1;
+ net_nfc_llcp_internal_socket_s *data;
+
+ data = pos->data;
+ if (data == NULL)
+ continue;
+
+ if (data->client_socket == socket)
+ break;
}
- else
+
+ if (pos == NULL)
+ return NULL;
+
+ return pos->data;
+}
+
+static void llcp_call_config(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_config_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_config_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish config: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
{
- return 0;
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
}
+
+ callback = (net_nfc_client_llcp_config_completed)func_data->callback;
+ callback(result, func_data->user_data);
}
-net_nfc_llcp_internal_socket_s * _find_internal_socket_info(net_nfc_llcp_socket_t socket)
+static void llcp_call_listen(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- net_nfc_llcp_internal_socket_s * inter_socket = NULL;
- net_nfc_llcp_internal_socket_s temp = { 0 };
- GList * found = NULL;
+ LlcpFuncData *func_data;
- DEBUG_CLIENT_MSG("Socket info search requested with #[ %d ]", socket);
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- temp.client_socket = socket;
+ net_nfc_client_llcp_listen_completed callback;
- if (socket_list != NULL)
+ if (net_nfc_gdbus_llcp_call_listen_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ &out_oal_socket,
+ res,
+ &error) == FALSE)
{
- found = g_list_find_custom(socket_list, &temp, __socket_equal_to);
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish listen: %s",
+ error->message);
+ g_error_free(error);
}
- if (NULL == found)
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
{
- DEBUG_CLIENT_MSG("ERROR DATA IS NOT FOUND");
- return NULL;
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
}
- else
+
+ socket_data->oal_socket = out_oal_socket;
+
+ func_data = user_data;
+ if (func_data == NULL)
{
- DEBUG_CLIENT_MSG("socket_info is found address [%p]", found->data);
- inter_socket = (net_nfc_llcp_internal_socket_s *)found->data;
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
}
- return inter_socket;
+ callback = (net_nfc_client_llcp_listen_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_connect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_connect_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_connect_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ &out_oal_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish connect: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ socket_data->oal_socket = out_oal_socket;
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_connect_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_connect_sap(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_connect_sap_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_connect_sap_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ &out_oal_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish connect sap: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ socket_data->oal_socket = out_oal_socket;
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_connect_sap_completed)
+ func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+
+static void llcp_call_send(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ guint32 out_client_socket;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_send_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_send_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish send: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_send_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_send_to(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ guint32 out_client_socket;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_send_to_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_send_to_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish send to: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_send_to_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_receive(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ GVariant *variant = NULL;
+ data_s data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_receive_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_receive_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &variant,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish receive: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+
+ callback = (net_nfc_client_llcp_receive_completed)func_data->callback;
+ callback(result, &data, func_data->user_data);
+
+ net_nfc_util_free_data(&data);
+
+ g_free(func_data);
+}
+
+static void llcp_call_receive_from(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ GVariant *variant = NULL;
+
+ sap_t sap;
+ data_s data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_llcp_receive_from_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_receive_from_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &sap,
+ &variant,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish receive from: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+
+ callback = (net_nfc_client_llcp_receive_from_completed)
+ func_data->callback;
+ callback(result, sap, &data, func_data->user_data);
+
+ net_nfc_util_free_data(&data);
+
+ g_free(func_data);
+}
+
+static void llcp_call_close(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_close_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_close_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish close: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_close_completed)func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+static void llcp_call_disconnect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ net_nfc_client_llcp_disconnect_completed callback;
+
+ if (net_nfc_gdbus_llcp_call_disconnect_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &out_client_socket,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish disconnect: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ socket_data = llcp_socket_data_find(out_client_socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return;
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not available");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_llcp_disconnect_completed)
+ func_data->callback;
+ callback(result, out_client_socket, func_data->user_data);
+}
+
+
+static void llcp_error(NetNfcGDbusLlcp *object,
+ guint arg_handle,
+ guint client_socket,
+ guint oal_socket,
+ gint error,
+ gpointer user_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+}
+
+/* Public APIs */
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_h config,
+ net_nfc_client_llcp_config_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ GVariant *variant = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (config == NULL)
+ {
+ DEBUG_ERR_MSG("Config is empty");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ memcpy(&llcp_config, config, sizeof(net_nfc_llcp_config_info_s));
+
+ variant = g_variant_new("(qqyy)",
+ config->miu,
+ config->wks,
+ config->lto,
+ config->option);
+
+ net_nfc_gdbus_llcp_call_config(llcp_proxy,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_config,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_config_sync
+ (net_nfc_llcp_config_info_h config)
+{
+ GVariant *variant = NULL;
+ GError *error = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ memcpy(&llcp_config, config, sizeof(net_nfc_llcp_config_info_s));
+
+ variant = g_variant_new("(qqyy)",
+ config->miu,
+ config->wks,
+ config->lto,
+ config->option);
+
+ if (net_nfc_gdbus_llcp_call_config_sync(llcp_proxy,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not config: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_config
+ (net_nfc_llcp_config_info_h *config)
+{
+ if (config == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ *config = (net_nfc_llcp_config_info_h)&llcp_config;
+
+ return NET_NFC_OK;
}
-static int __socket_equal_to_by_oal(gconstpointer key1, gconstpointer key2)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_listen(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ sap_t sap,
+ net_nfc_client_llcp_listen_completed callback,
+ void *user_data)
{
- net_nfc_llcp_internal_socket_s * arg1 = (net_nfc_llcp_internal_socket_s *)key1;
- net_nfc_llcp_internal_socket_s * arg2 = (net_nfc_llcp_internal_socket_s *)key2;
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- if (arg1->oal_socket < arg2->oal_socket)
+ if (llcp_proxy == NULL)
{
- return -1;
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
}
- else if (arg1->oal_socket > arg2->oal_socket)
+
+ if (service_name == NULL)
{
- return 1;
+ DEBUG_ERR_MSG("service_name is empty");
+ return NET_NFC_UNKNOWN_ERROR;
}
- else
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- return 0;
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
}
-}
-
-static void __socket_foreach(gpointer data, gpointer user_data)
-{
- __free_socket_info((net_nfc_llcp_internal_socket_s *)data);
-}
-void _net_nfc_llcp_close_all_socket()
-{
- pthread_mutex_lock(&llcp_lock);
+ /* FIXME: temporary typecast to (uint8_t *) */
+ socket_data->service_name = (uint8_t *)g_strdup(service_name);
+ socket_data->sap = sap;
- if (socket_list != NULL)
- {
- g_list_foreach(socket_list, __socket_foreach, NULL);
- g_list_free(socket_list);
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
}
- socket_list = NULL;
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- pthread_mutex_unlock(&llcp_lock);
+ net_nfc_gdbus_llcp_call_listen(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ socket_data->sap,
+ service_name,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_listen,
+ func_data);
+
+ return NET_NFC_OK;
}
-net_nfc_llcp_internal_socket_s * _find_internal_socket_info_by_oal_socket(net_nfc_llcp_socket_t socket)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_listen_sync(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ sap_t sap,
+ net_nfc_llcp_socket_t *out_socket)
{
- net_nfc_llcp_internal_socket_s * inter_socket = NULL;
- net_nfc_llcp_internal_socket_s temp = { 0 };
- GList * found = NULL;
+ GError *error = NULL;
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
- temp.oal_socket = socket;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
- DEBUG_CLIENT_MSG("search by oal socket is called socket[ %d ] ", socket);
-
- if (socket_list != NULL)
+ if (llcp_proxy == NULL)
{
- found = g_list_find_custom(socket_list, &temp, __socket_equal_to_by_oal);
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
}
- if (NULL == found)
+ if (service_name == NULL)
{
- DEBUG_CLIENT_MSG("ERROR DATA IS NOT FOUND");
- return NULL;
+ DEBUG_ERR_MSG("service_name is empty");
+ return NET_NFC_UNKNOWN_ERROR;
}
- else
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- inter_socket = (net_nfc_llcp_internal_socket_s *)found->data;
- DEBUG_CLIENT_MSG("oal socket_info is found address [%p]", inter_socket);
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
}
- return inter_socket;
-}
+ /* FIXME: temporary typecast to (uint8_t *) */
+ socket_data->service_name = (uint8_t *)g_strdup(service_name);
+ socket_data->sap = sap;
-void _remove_internal_socket(net_nfc_llcp_internal_socket_s * data)
-{
- pthread_mutex_lock(&llcp_lock);
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- if (data == NULL)
+ if (net_nfc_gdbus_llcp_call_listen_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ socket_data->sap,
+ service_name,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ &out_oal_socket,
+ NULL,
+ &error) == FALSE)
{
- pthread_mutex_unlock(&llcp_lock);
- return;
+ DEBUG_ERR_MSG("can not listen: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
- if (socket_list != NULL)
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
{
-
- socket_list = g_list_remove(socket_list, data);
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
}
- __free_socket_info(data);
- pthread_mutex_unlock(&llcp_lock);
+ out_socket_data->oal_socket = out_oal_socket;
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+
+ return NET_NFC_OK;
}
-void _append_internal_socket(net_nfc_llcp_internal_socket_s * data)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_connect(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ net_nfc_client_llcp_connect_completed callback,
+ void *user_data)
{
- pthread_mutex_lock(&llcp_lock);
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- if (data != NULL)
+ if (llcp_proxy == NULL)
{
- socket_list = g_list_append(socket_list, data);
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
}
- pthread_mutex_unlock(&llcp_lock);
+ if (service_name == NULL)
+ {
+ DEBUG_ERR_MSG("service_name is empty");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_connect(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ service_name,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_connect,
+ func_data);
+
+ return NET_NFC_OK;
}
-/* =============================================================== */
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_socket(net_nfc_llcp_socket_t * socket, net_nfc_llcp_socket_option_h options)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_connect_sync(net_nfc_llcp_socket_t socket,
+ const char *service_name,
+ net_nfc_llcp_socket_t *out_socket)
{
+ GError *error = NULL;
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
- net_nfc_llcp_internal_socket_s * socket_data = NULL;
- net_nfc_llcp_socket_option_s * strct_options = (net_nfc_llcp_socket_option_s *)options;
- net_nfc_llcp_socket_option_s default_option = {
- 128, 1, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED
- };
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
- DEBUG_CLIENT_MSG("function %s is called", __func__);
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- if (socket == NULL)
+ if (service_name == NULL)
{
- return NET_NFC_NULL_PARAMETER;
+ DEBUG_ERR_MSG("service_name is empty");
+ return NET_NFC_UNKNOWN_ERROR;
}
- if (options == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- strct_options = &default_option;
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
}
- _net_nfc_util_alloc_mem(socket_data, sizeof(net_nfc_llcp_internal_socket_s));
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- socket_data->client_socket = socket_handle++;
- socket_data->miu = strct_options->miu;
- socket_data->rw = strct_options->rw;
- socket_data->type = strct_options->type;
- socket_data->device_id = current_target;
- socket_data->close_requested = false;
+ if (net_nfc_gdbus_llcp_call_connect_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ service_name,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ &out_oal_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not connect: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- _append_internal_socket(socket_data);
+ out_socket_data->oal_socket = out_oal_socket;
- *socket = socket_data->client_socket;
+ if (out_socket)
+ *out_socket = out_client_socket;
return NET_NFC_OK;
-
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_socket_callback(net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_cb cb, void * user_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_connect_sap(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ net_nfc_client_llcp_connect_sap_completed callback,
+ void *user_data)
{
- net_nfc_llcp_internal_socket_s * socket_data = NULL;
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- if (cb == NULL)
+ if (llcp_proxy == NULL)
{
- return NET_NFC_NULL_PARAMETER;
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
}
- pthread_mutex_lock(&llcp_lock);
-
- socket_data = _find_internal_socket_info(socket);
-
+ socket_data = llcp_socket_data_find(socket);
if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- socket_data->cb = cb;
- socket_data->register_param = user_param;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- pthread_mutex_unlock(&llcp_lock);
+ net_nfc_gdbus_llcp_call_connect_sap(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ sap,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_connect_sap,
+ func_data);
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_llcp_socket_callback(net_nfc_llcp_socket_t socket)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_connect_sap_sync(
+ net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ net_nfc_llcp_socket_t *out_socket)
{
- pthread_mutex_lock(&llcp_lock);
- net_nfc_llcp_internal_socket_s * socket_data = _find_internal_socket_info(socket);
+ GError *error = NULL;
+ guint32 out_client_socket;
+ guint32 out_oal_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- if (socket_data->cb == NULL)
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_connect_sap_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ socket_data->miu,
+ socket_data->rw,
+ socket_data->type,
+ sap,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ &out_oal_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not connect: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
{
- pthread_mutex_unlock(&llcp_lock);
- return NET_NFC_NOT_REGISTERED;
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
}
- socket_data->cb = NULL;
- pthread_mutex_unlock(&llcp_lock);
+ out_socket_data->oal_socket = out_oal_socket;
+
+ if (out_socket)
+ *out_socket = out_client_socket;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_listen_llcp(net_nfc_llcp_socket_t socket, const char *service_name, sap_t sap, void *trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_send(net_nfc_llcp_socket_t socket,
+ data_h data,
+ net_nfc_client_llcp_send_completed callback,
+ void *user_data)
{
- net_nfc_llcp_internal_socket_s *psocket_data = NULL;
- net_nfc_request_listen_socket_t *request = NULL;
- net_nfc_error_e ret;
- int srv_name_count = 0;
- uint32_t length = 0;
-
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
+ LlcpFuncData *func_data;
+ GVariant *variant = NULL;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- if (service_name == NULL)
+ if (llcp_proxy == NULL)
{
- return NET_NFC_NULL_PARAMETER;
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
}
- pthread_mutex_lock(&llcp_lock);
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- srv_name_count = strlen((char *)service_name) + 1;
-
- _net_nfc_util_alloc_mem(psocket_data->service_name, srv_name_count);
- if (psocket_data->service_name == NULL)
+ if (data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
- return NET_NFC_ALLOC_FAIL;
+ DEBUG_ERR_MSG("data is empty");
+ return NET_NFC_INVALID_PARAM;
}
- strncpy((char *)psocket_data->service_name, (char *)service_name, srv_name_count);
- psocket_data->sap = sap;
- /* fill request message */
- length = sizeof(net_nfc_request_listen_socket_t) + srv_name_count;
-
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ if (variant == NULL)
{
- _net_nfc_util_free_mem(psocket_data->service_name);
- pthread_mutex_unlock(&llcp_lock);
- return NET_NFC_ALLOC_FAIL;
+ DEBUG_ERR_MSG("Can not convert to variant");
+ return NET_NFC_INVALID_PARAM;
}
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_LLCP_LISTEN;
- request->handle = current_target;
- request->miu = psocket_data->miu;
- request->oal_socket = psocket_data->oal_socket;
- request->rw = psocket_data->rw;
- request->sap = psocket_data->sap;
- request->type = psocket_data->type;
- request->client_socket = psocket_data->client_socket;
- request->trans_param = trans_param;
- request->service_name.length = srv_name_count;
- memcpy(&request->service_name.buffer, psocket_data->service_name, request->service_name.length);
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
+ net_nfc_gdbus_llcp_call_send(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_send,
+ func_data);
- _net_nfc_util_free_mem(request);
-
- pthread_mutex_unlock(&llcp_lock);
-
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_disconnect_llcp(net_nfc_llcp_socket_t socket, void * trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_send_sync(net_nfc_llcp_socket_t socket,
+ data_h data,
+ net_nfc_llcp_socket_t *out_socket)
{
- net_nfc_llcp_internal_socket_s *psocket_data;
- net_nfc_request_disconnect_socket_t request = { 0, };
- net_nfc_error_e ret;
+ GVariant *variant;
+ GError *error = NULL;
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data;
+ net_nfc_llcp_internal_socket_s *out_socket_data;
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- pthread_mutex_lock(&llcp_lock);
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- request.length = sizeof(net_nfc_request_disconnect_socket_t);
- request.request_type = NET_NFC_MESSAGE_LLCP_DISCONNECT;
- request.handle = current_target;
- request.oal_socket = psocket_data->oal_socket;
- request.client_socket = psocket_data->client_socket;
- request.trans_param = trans_param;
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is empty");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ if (variant == NULL)
+ {
+ DEBUG_ERR_MSG("Can not convert to variant");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ if (net_nfc_gdbus_llcp_call_send_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call send: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not find socket_data");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- pthread_mutex_unlock(&llcp_lock);
+ if (out_socket)
+ *out_socket = out_client_socket;
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_close_llcp_socket(net_nfc_llcp_socket_t socket, void * trans_param)
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ data_h data,
+ net_nfc_client_llcp_send_to_completed callback,
+ void *user_data)
{
- net_nfc_llcp_internal_socket_s *psocket_data = NULL;
- net_nfc_request_close_socket_t request = { 0, };
- net_nfc_error_e ret;
+ LlcpFuncData *func_data;
+ GVariant *variant = NULL;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- pthread_mutex_lock(&llcp_lock);
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- if (psocket_data->close_requested)
+ if (data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
- return NET_NFC_OK;
+ DEBUG_ERR_MSG("data is empty");
+ return NET_NFC_INVALID_PARAM;
}
- psocket_data->close_requested = true;
- request.length = sizeof(net_nfc_request_close_socket_t);
- request.request_type = NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE;
- request.handle = current_target;
- request.oal_socket = psocket_data->oal_socket;
- request.client_socket = psocket_data->client_socket;
- request.trans_param = trans_param;
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ if (variant == NULL)
+ {
+ DEBUG_ERR_MSG("Can not convert to variant");
+ return NET_NFC_INVALID_PARAM;
+ }
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- _remove_internal_socket(psocket_data);
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- pthread_mutex_unlock(&llcp_lock);
+ net_nfc_gdbus_llcp_call_send_to(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ sap,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_send_to,
+ func_data);
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_llcp(net_nfc_llcp_socket_t socket, data_h data, void * trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_send_to_sync(net_nfc_llcp_socket_t socket,
+ sap_t sap,
+ data_h data,
+ net_nfc_llcp_socket_t *out_socket)
{
- net_nfc_llcp_internal_socket_s *psocket_data;
- net_nfc_request_send_socket_t *request = NULL;
- data_s *data_private = (data_s *)data;
- net_nfc_error_e ret;
- uint32_t length = 0;
+ GVariant *variant;
+ GError *error = NULL;
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data;
+ net_nfc_llcp_internal_socket_s *out_socket_data;
- if (data_private == NULL || data_private->buffer == NULL || data_private->length == 0)
+ if (llcp_proxy == NULL)
{
- return NET_NFC_NULL_PARAMETER;
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
}
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
-
- pthread_mutex_lock(&llcp_lock);
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- /* fill request message */
- length = sizeof(net_nfc_request_send_socket_t) + data_private->length;
-
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
+ if (data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
- return NET_NFC_ALLOC_FAIL;
+ DEBUG_ERR_MSG("data is empty");
+ return NET_NFC_INVALID_PARAM;
}
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_LLCP_SEND;
- request->handle = current_target;
- request->oal_socket = psocket_data->oal_socket;
- request->client_socket = psocket_data->client_socket;
- request->trans_param = trans_param;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- request->data.length = data_private->length;
- memcpy(&request->data.buffer, data_private->buffer, request->data.length);
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ if (variant == NULL)
+ {
+ DEBUG_ERR_MSG("Can not convert to variant");
+ return NET_NFC_INVALID_PARAM;
+ }
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
+ if (net_nfc_gdbus_llcp_call_send_to_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ sap,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call send to: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- _net_nfc_util_free_mem(request);
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not find socket_data");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- pthread_mutex_unlock(&llcp_lock);
+ if (out_socket)
+ *out_socket = out_client_socket;
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_receive_llcp(net_nfc_llcp_socket_t socket, size_t req_length, void * trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_receive(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ net_nfc_client_llcp_receive_completed callback,
+ void *user_data)
{
- net_nfc_llcp_internal_socket_s *psocket_data = NULL;
- net_nfc_request_receive_socket_t request = { 0, };
- net_nfc_error_e ret;
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
-
- pthread_mutex_lock(&llcp_lock);
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- request.length = sizeof(net_nfc_request_receive_socket_t);
- request.request_type = NET_NFC_MESSAGE_LLCP_RECEIVE;
- request.handle = current_target;
- request.oal_socket = psocket_data->oal_socket;
- request.client_socket = psocket_data->client_socket;
- request.trans_param = trans_param;
- request.req_length = req_length;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- pthread_mutex_unlock(&llcp_lock);
+ net_nfc_gdbus_llcp_call_receive(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ request_length,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_receive,
+ func_data);
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_to_llcp(net_nfc_llcp_socket_t socket, sap_t dsap, data_h data, void *trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_receive_sync(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ data_h *out_data)
{
- net_nfc_llcp_internal_socket_s *psocket_data = NULL;
- net_nfc_request_send_to_socket_t *request = NULL;
- data_s * data_private = (data_s *)data;
- net_nfc_error_e ret;
- uint32_t length = 0;
+ GVariant *variant = NULL;
+ GError *error = NULL;
+ net_nfc_llcp_internal_socket_s *socket_data;
- if (data_private == NULL || data_private->buffer == NULL || data_private->length == 0)
+ if (llcp_proxy == NULL)
{
- return NET_NFC_NULL_PARAMETER;
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
}
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
-
- pthread_mutex_lock(&llcp_lock);
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- /* fill request message */
- length = sizeof(net_nfc_request_send_to_socket_t) + data_private->length;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_receive_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ request_length,
+ net_nfc_client_gdbus_get_privilege(),
+ &variant,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call receive: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
+ if (out_data)
{
- pthread_mutex_unlock(&llcp_lock);
- return NET_NFC_ALLOC_FAIL;
+ *out_data = net_nfc_util_gdbus_variant_to_data(variant);
}
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_LLCP_SEND_TO;
- request->handle = current_target;
- request->oal_socket = psocket_data->oal_socket;
- request->client_socket = psocket_data->client_socket;
- request->trans_param = trans_param;
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_receive_from(net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ net_nfc_client_llcp_receive_from_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- request->data.length = data_private->length;
- memcpy(&request->data.buffer, data_private->buffer, request->data.length);
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
- _net_nfc_util_free_mem(request);
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- pthread_mutex_unlock(&llcp_lock);
+ net_nfc_gdbus_llcp_call_receive_from(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ request_length,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_receive_from,
+ func_data);
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_receive_from_llcp(net_nfc_llcp_socket_t socket, sap_t ssap, size_t req_length, void * trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_receive_from_sync
+ (net_nfc_llcp_socket_t socket,
+ size_t request_length,
+ sap_t *out_sap,
+ data_h *out_data)
{
- net_nfc_llcp_internal_socket_s *psocket_data = NULL;
- net_nfc_request_receive_from_socket_t request = { 0, };
- net_nfc_error_e ret;
+ GVariant *variant = NULL;
+ GError *error = NULL;
+ sap_t sap;
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
+ net_nfc_llcp_internal_socket_s *socket_data;
- pthread_mutex_lock(&llcp_lock);
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- request.length = sizeof(net_nfc_request_receive_from_socket_t);
- request.request_type = NET_NFC_MESSAGE_LLCP_RECEIVE_FROM;
- request.handle = current_target;
- request.oal_socket = psocket_data->oal_socket;
- request.client_socket = psocket_data->client_socket;
- request.trans_param = trans_param;
- request.req_length = req_length;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_receive_from_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ request_length,
+ net_nfc_client_gdbus_get_privilege(),
+ &sap,
+ &variant,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call receive from: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ if (*out_sap)
+ *out_sap = sap;
- pthread_mutex_unlock(&llcp_lock);
+ if (out_data)
+ {
+ *out_data = net_nfc_util_gdbus_variant_to_data(variant);
+ }
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_connect_llcp_with_sap(net_nfc_llcp_socket_t socket, sap_t sap, void * trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_close(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_close_completed callback,
+ void *user_data)
{
- net_nfc_llcp_internal_socket_s *psocket_data = NULL;
- net_nfc_request_connect_sap_socket_t request = { 0, };
- net_nfc_error_e ret;
-
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- pthread_mutex_lock(&llcp_lock);
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- request.length = sizeof(net_nfc_request_connect_sap_socket_t);
- request.request_type = NET_NFC_MESSAGE_LLCP_CONNECT_SAP;
- request.handle = current_target;
- request.oal_socket = psocket_data->oal_socket;
- request.sap = sap;
- request.client_socket = psocket_data->client_socket;
- request.trans_param = trans_param;
- request.miu = psocket_data->miu;
- request.rw = psocket_data->rw;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- pthread_mutex_unlock(&llcp_lock);
+ net_nfc_gdbus_llcp_call_close(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_close,
+ func_data);
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_connect_llcp(net_nfc_llcp_socket_t socket, const char *service_name, void *trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_close_sync(net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_t *out_socket)
{
- net_nfc_llcp_internal_socket_s *psocket_data = NULL;
- net_nfc_request_connect_socket_t *request = NULL;
- net_nfc_error_e ret;
- uint32_t length = 0, svc_name_length = 0;
+ GError *error = NULL;
+ guint32 out_client_socket;
- DEBUG_CLIENT_MSG("function %s is called. socket#[ %d ]", __func__, socket);
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
- pthread_mutex_lock(&llcp_lock);
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
{
- pthread_mutex_unlock(&llcp_lock);
+ DEBUG_ERR_MSG("can not get socket_data");
return NET_NFC_LLCP_INVALID_SOCKET;
}
- svc_name_length = strlen(service_name) + 1;
-
- /* fill request message */
- length = sizeof(net_nfc_request_connect_socket_t) + svc_name_length;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
+ if (net_nfc_gdbus_llcp_call_close_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ NULL,
+ &error) == FALSE)
{
- pthread_mutex_unlock(&llcp_lock);
- return NET_NFC_ALLOC_FAIL;
+ DEBUG_ERR_MSG("can not close: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_LLCP_CONNECT;
- request->handle = current_target;
- request->oal_socket = psocket_data->oal_socket;
- request->client_socket = psocket_data->client_socket;
- request->trans_param = trans_param;
- request->miu = psocket_data->miu;
- request->rw = psocket_data->rw;
-
- request->service_name.length = svc_name_length;
- memcpy(&request->service_name.buffer, service_name, request->service_name.length);
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
-
- _net_nfc_util_free_mem(request);
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- pthread_mutex_unlock(&llcp_lock);
+ if (out_socket)
+ *out_socket = out_client_socket;
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_local_configure(net_nfc_llcp_config_info_h * config)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_disconnect(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_disconnect_completed callback,
+ void *user_data)
{
- if (config == NULL)
+ LlcpFuncData *func_data;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+
+ if (llcp_proxy == NULL)
{
- return NET_NFC_NULL_PARAMETER;
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
}
- *config = (net_nfc_llcp_config_info_h)&local_config;
+ func_data = g_new0(LlcpFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_disconnect(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_disconnect,
+ func_data);
return NET_NFC_OK;
}
-void _net_nfc_set_llcp_remote_configure(net_nfc_llcp_config_info_s * remote_data)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_disconnect_sync(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_t *out_socket)
{
- if (remote_data == NULL)
+ GError *error = NULL;
+ guint32 out_client_socket;
+
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+
+ if (llcp_proxy == NULL)
{
- DEBUG_CLIENT_MSG("recieved data is NULL");
- return;
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+ return NET_NFC_UNKNOWN_ERROR;
}
- remote_config.lto = remote_data->lto;
- remote_config.wks = remote_data->wks;
- remote_config.miu = remote_data->miu;
- remote_config.option = remote_data->option;
-}
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get socket_data");
+ return NET_NFC_LLCP_INVALID_SOCKET;
+ }
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_remote_configure(net_nfc_target_handle_h handle, net_nfc_llcp_config_info_h * config)
-{
- if (config == NULL || handle == NULL)
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_disconnect_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket_data->client_socket,
+ socket_data->oal_socket,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_client_socket,
+ NULL,
+ &error) == FALSE)
{
- return NET_NFC_NULL_PARAMETER;
+ DEBUG_ERR_MSG("can not disconnect: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
- if (current_target == NULL || (net_nfc_target_handle_s*)handle != current_target)
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
{
- return NET_NFC_INVALID_HANDLE;
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
}
- *config = (net_nfc_llcp_config_info_h)&remote_config;
+ if (out_socket)
+ *out_socket = out_client_socket;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_local_configure(net_nfc_llcp_config_info_h config, void * trans_param)
+NET_NFC_EXPORT_API
+void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket,
+ net_nfc_llcp_socket_option_h option)
{
- net_nfc_request_config_llcp_t request = { 0, };
- net_nfc_error_e ret;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
- DEBUG_CLIENT_MSG("function %s is called", __func__);
+ socket_data = g_new0(net_nfc_llcp_internal_socket_s, 1);
+
+ socket_data->client_socket = socket_handle++;
+
+ if (option)
+ {
+ socket_data->miu = option->miu;
+ socket_data->rw = option->rw;
+ socket_data->type = option->type;
+ }
+ else
+ {
+ socket_data->miu = 128;
+ socket_data->rw = 1;
+ socket_data->type =
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED;
+ }
+
+ socket_data->device_id = llcp_handle;
+ socket_data->close_requested = false;
+
+
+ if (socket)
+ *socket = socket_data->client_socket;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_local_config(
+ net_nfc_llcp_config_info_h *config)
+{
if (config == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- request.length = sizeof(net_nfc_request_config_llcp_t);
- request.request_type = NET_NFC_MESSAGE_LLCP_CONFIG;
- memset(&request, 0x0, sizeof(net_nfc_request_config_llcp_t));
- memcpy(&local_config, config, sizeof(net_nfc_llcp_config_info_s));
- request.trans_param = trans_param;
- memcpy(&(request.config), config, sizeof(net_nfc_llcp_config_info_s));
+ *config = (net_nfc_llcp_config_info_h)&llcp_config;
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_local_socket_option(net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * info)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_local_socket_option(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_option_h *info)
{
- net_nfc_llcp_internal_socket_s *psocket_data = NULL;
+ net_nfc_llcp_internal_socket_s *socket_data = NULL;
DEBUG_CLIENT_MSG("function %s is called", __func__);
- psocket_data = _find_internal_socket_info(socket);
- if (psocket_data == NULL)
+ socket_data = llcp_socket_data_find(socket);
+ if (socket_data == NULL)
return NET_NFC_LLCP_INVALID_SOCKET;
- *info = (net_nfc_llcp_socket_option_h)psocket_data;
+ *info = (net_nfc_llcp_socket_option_h)socket_data;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_remote_socket_option(net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_h * info)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_create_socket_option(
+ net_nfc_llcp_socket_option_h *option,
+ uint16_t miu,
+ uint8_t rw,
+ net_nfc_socket_type_e type)
{
- info = NULL;
- return NET_NFC_OK;
-}
+ net_nfc_llcp_socket_option_s *struct_option = NULL;
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_socket_option(net_nfc_llcp_socket_option_h * option, uint16_t miu, uint8_t rw, net_nfc_socket_type_e type)
-{
if (option == NULL)
{
return NET_NFC_NULL_PARAMETER;
if (miu < 128 || miu > 1152 ||
rw < 1 || rw > 15 ||
- type < NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED || type > NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS)
+ type < NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED ||
+ type > NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS)
{
return NET_NFC_OUT_OF_BOUND;
}
- net_nfc_llcp_socket_option_s * struct_option = NULL;
-
_net_nfc_util_alloc_mem(struct_option, sizeof(net_nfc_llcp_socket_option_s));
if (struct_option != NULL)
{
}
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_socket_option_default(net_nfc_llcp_socket_option_h * option)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_create_socket_option_default(
+ net_nfc_llcp_socket_option_h *option)
{
- return net_nfc_create_llcp_socket_option(option, 128, 1, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED);
+ return net_nfc_client_llcp_create_socket_option(
+ option,
+ 128,
+ 1,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_socket_option_miu(net_nfc_llcp_socket_option_h option, uint16_t * miu)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_miu(
+ net_nfc_llcp_socket_option_h option,
+ uint16_t *miu)
{
if (option == NULL || miu == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
*miu = struct_option->miu;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_socket_option_miu(net_nfc_llcp_socket_option_h option, uint16_t miu)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_miu(
+ net_nfc_llcp_socket_option_h option,
+ uint16_t miu)
{
if (option == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
struct_option->miu = miu;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_socket_option_rw(net_nfc_llcp_socket_option_h option, uint8_t * rw)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_rw(
+ net_nfc_llcp_socket_option_h option,
+ uint8_t *rw)
{
if (option == NULL || rw == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
*rw = struct_option->rw;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_socket_option_rw(net_nfc_llcp_socket_option_h option, uint8_t rw)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_rw(
+ net_nfc_llcp_socket_option_h option,
+ uint8_t rw)
{
if (option == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
struct_option->rw = rw;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_socket_option_type(net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e * type)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_socket_option_type(
+ net_nfc_llcp_socket_option_h option,
+ net_nfc_socket_type_e * type)
{
if (option == NULL || type == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
*type = struct_option->type;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_socket_option_type(net_nfc_llcp_socket_option_h option, net_nfc_socket_type_e type)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_set_socket_option_type(
+ net_nfc_llcp_socket_option_h option,
+ net_nfc_socket_type_e type)
{
if (option == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_socket_option_s * struct_option = (net_nfc_llcp_socket_option_s *)option;
+ net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
struct_option->type = type;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_llcp_socket_option(net_nfc_llcp_socket_option_h option)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_free_socket_option(
+ net_nfc_llcp_socket_option_h option)
{
if (option == NULL)
{
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_configure(net_nfc_llcp_config_info_h * config, uint16_t miu, uint16_t wks, uint8_t lto, uint8_t option)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_create_config(
+ net_nfc_llcp_config_info_h *config,
+ uint16_t miu,
+ uint16_t wks,
+ uint8_t lto,
+ uint8_t option)
{
if (config == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_config_info_s ** config_private = (net_nfc_llcp_config_info_s **)config;
+ net_nfc_llcp_config_info_s **tmp_config =
+ (net_nfc_llcp_config_info_s **)config;
+
+ _net_nfc_util_alloc_mem(*tmp_config,
+ sizeof(net_nfc_llcp_config_info_s));
- _net_nfc_util_alloc_mem(*config_private, sizeof (net_nfc_llcp_config_info_s));
- if (*config_private == NULL)
+ if (*tmp_config == NULL)
return NET_NFC_ALLOC_FAIL;
- (*config_private)->miu = miu;
- (*config_private)->wks = wks;
- (*config_private)->lto = lto;
- (*config_private)->option = option;
+ (*tmp_config)->miu = miu;
+ (*tmp_config)->wks = wks;
+ (*tmp_config)->lto = lto;
+ (*tmp_config)->option = option;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_llcp_configure_default(net_nfc_llcp_config_info_h * config)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_create_config_default(net_nfc_llcp_config_info_h *config)
{
- return net_nfc_create_llcp_configure(config, 128, 1, 10, 0);
+ return net_nfc_client_llcp_create_config(config, 128, 1, 10, 0);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_miu(net_nfc_llcp_config_info_h config, uint16_t * miu)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_config_miu(
+ net_nfc_llcp_config_info_h config,
+ uint16_t *miu)
{
if (config == NULL || miu == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;
- *miu = config_private->miu;
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ *miu = tmp_config->miu;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_wks(net_nfc_llcp_config_info_h config, uint16_t * wks)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_config_wks(
+ net_nfc_llcp_config_info_h config,
+ uint16_t *wks)
{
if (config == NULL || wks == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;
- *wks = config_private->wks;
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ *wks = tmp_config->wks;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_lto(net_nfc_llcp_config_info_h config, uint8_t * lto)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_config_lto(
+ net_nfc_llcp_config_info_h config,
+ uint8_t *lto)
{
if (config == NULL || lto == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;
- *lto = config_private->lto;
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ *lto = tmp_config->lto;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_llcp_configure_option(net_nfc_llcp_config_info_h config, uint8_t * option)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_get_config_option(
+ net_nfc_llcp_config_info_h config,
+ uint8_t *option)
{
if (config == NULL || option == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;
- *option = config_private->option;
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ *option = tmp_config->option;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_miu(net_nfc_llcp_config_info_h config, uint16_t miu)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_set_config_miu(
+ net_nfc_llcp_config_info_h config,
+ uint16_t miu)
{
if (config == NULL)
{
return NET_NFC_OUT_OF_BOUND;
}
- net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;
- config_private->miu = miu;
+ net_nfc_llcp_config_info_s * tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ tmp_config->miu = miu;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_wks(net_nfc_llcp_config_info_h config, uint16_t wks)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_set_config_wks(
+ net_nfc_llcp_config_info_h config,
+ uint16_t wks)
{
if (config == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;
- config_private->wks = wks;
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ tmp_config->wks = wks;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_lto(net_nfc_llcp_config_info_h config, uint8_t lto)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_set_config_lto(
+ net_nfc_llcp_config_info_h config,
+ uint8_t lto)
{
if (config == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;
- config_private->lto = lto;
+ net_nfc_llcp_config_info_s *tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ tmp_config->lto = lto;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_llcp_configure_option(net_nfc_llcp_config_info_h config, uint8_t option)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_set_config_option(
+ net_nfc_llcp_config_info_h config,
+ uint8_t option)
{
if (config == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_config_info_s * config_private = (net_nfc_llcp_config_info_s *)config;
- config_private->option = option;
+ net_nfc_llcp_config_info_s * tmp_config =
+ (net_nfc_llcp_config_info_s *)config;
+
+ tmp_config->option = option;
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_llcp_configure(net_nfc_llcp_config_info_h config)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_llcp_free_config(net_nfc_llcp_config_info_h config)
{
if (config == NULL)
{
return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_target_handle(void *trans_param)
+net_nfc_error_e net_nfc_client_llcp_init(void)
{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_request_get_current_target_handle_t request = { 0, };
-
- request.length = sizeof(net_nfc_request_get_current_target_handle_t);
- request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE;
- request.trans_param = trans_param;
+ GError *error = NULL;
- result = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_target_handle_sync(net_nfc_target_handle_h *handle)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_request_get_current_target_handle_t request = { 0, };
- net_nfc_response_get_current_target_handle_t response = { 0, };
+ if (llcp_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+ return NET_NFC_OK;
+ }
- request.length = sizeof(net_nfc_request_get_current_target_handle_t);
- request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE;
- request.trans_param = (void *)&response;
+ llcp_proxy = net_nfc_gdbus_llcp_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Llcp",
+ NULL,
+ &error);
- result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL);
- if (result == NET_NFC_OK)
+ if (llcp_proxy == NULL)
{
- *handle = (net_nfc_target_handle_h)response.handle;
- result = response.result;
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
- return result;
+ g_signal_connect(llcp_proxy, "error",
+ G_CALLBACK(llcp_error), NULL);
+
+ return NET_NFC_OK;
}
-void _net_nfc_set_llcp_current_target_id(net_nfc_target_handle_s * handle)
+void net_nfc_client_llcp_deinit(void)
{
- current_target = handle;
+ if (llcp_proxy)
+ {
+ g_object_unref(llcp_proxy);
+ llcp_proxy = NULL;
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_context.h"
+#include "net_nfc_client_manager.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+typedef struct _ManagerFuncData ManagerFuncData;
+
+struct _ManagerFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusManager *manager_proxy = NULL;
+static gboolean activation_is_running = FALSE;
+
+static ManagerFuncData *activated_func_data = NULL;
+
+static int is_activated = -1;
+
+static void manager_call_set_active_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void manager_call_get_server_state_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+
+static void manager_activated(NetNfcGDbusManager *manager,
+ gboolean activated,
+ gpointer user_data);
+
+
+static void manager_call_set_active_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ ManagerFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_manager_set_active_completed callback;
+ gpointer data;
+
+ activation_is_running = FALSE;
+
+ if (net_nfc_gdbus_manager_call_set_active_finish(
+ NET_NFC_GDBUS_MANAGER(source_object),
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish call_set_active: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+
+ callback = (net_nfc_client_manager_set_active_completed)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(result, data);
+
+ g_free(func_data);
+}
+
+static void manager_call_get_server_state_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ ManagerFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ guint out_state;
+ GError *error = NULL;
+
+ net_nfc_client_manager_get_server_state_completed callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_manager_call_get_server_state_finish(
+ NET_NFC_GDBUS_MANAGER(source_object),
+ &out_state,
+ res,
+ &error) == FALSE)
+ {
+
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish get_server_state: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_manager_get_server_state_completed)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(result, out_state, data);
+
+ g_free(func_data);
+}
+
+
+static void manager_activated(NetNfcGDbusManager *manager,
+ gboolean activated,
+ gpointer user_data)
+{
+ bool state = false;
+
+ INFO_MSG(">>> SIGNAL arrived");
+ DEBUG_CLIENT_MSG("activated %d", activated);
+
+ /* update current state */
+ is_activated = (int)activated;
+
+ if (activated_func_data == NULL)
+ return;
+
+ if (activated == TRUE)
+ state = true;
+
+ if (activated_func_data->callback)
+ {
+ net_nfc_client_manager_activated callback;
+ gpointer user_data;
+
+ callback = (net_nfc_client_manager_activated)
+ (activated_func_data->callback);
+ user_data = activated_func_data->user_data;
+
+ callback(state, user_data);
+ }
+}
+
+NET_NFC_EXPORT_API
+void net_nfc_client_manager_set_activated(
+ net_nfc_client_manager_activated callback,
+ void *user_data)
+{
+ if (activated_func_data == NULL)
+ activated_func_data = g_new0(ManagerFuncData, 1);
+
+ activated_func_data->callback = (gpointer)callback;
+ activated_func_data->user_data = user_data;
+}
+
+NET_NFC_EXPORT_API
+void net_nfc_client_manager_unset_activated(void)
+{
+ if (activated_func_data == NULL)
+ {
+ DEBUG_ERR_MSG("manager_func_data is not initialized");
+ return;
+ }
+
+ g_free(activated_func_data);
+ activated_func_data = NULL;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_manager_set_active(int state,
+ net_nfc_client_manager_set_active_completed callback,
+ void *user_data)
+{
+ gboolean active = FALSE;
+ ManagerFuncData *func_data;
+
+ if (manager_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* allow this function even nfc is off */
+
+ if (activation_is_running == TRUE)
+ return NET_NFC_BUSY;
+
+ activation_is_running = TRUE;
+
+ func_data = g_new0(ManagerFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ if (state == true)
+ active = TRUE;
+
+ net_nfc_gdbus_manager_call_set_active(manager_proxy,
+ active,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ manager_call_set_active_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_manager_set_active_sync(int state)
+{
+ GError *error = NULL;
+
+ if (manager_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* allow this function even nfc is off */
+
+ if (net_nfc_gdbus_manager_call_set_active_sync(manager_proxy,
+ (gboolean)state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call SetActive: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_manager_get_server_state(
+ net_nfc_client_manager_get_server_state_completed callback,
+ void *user_data)
+{
+ ManagerFuncData *func_data;
+
+ if (manager_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(ManagerFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer) callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_manager_call_get_server_state(manager_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ manager_call_get_server_state_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_manager_get_server_state_sync(
+ unsigned int *state)
+{
+ GError *error = NULL;
+ guint out_state;
+
+ if (manager_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_manager_call_get_server_state_sync(manager_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_state,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call GetServerState: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ *state = out_state;
+ return NET_NFC_OK;
+
+}
+
+net_nfc_error_e net_nfc_client_manager_init(void)
+{
+ GError *error = NULL;
+
+ if (manager_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+ return NET_NFC_OK;
+ }
+
+ manager_proxy = net_nfc_gdbus_manager_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Manager",
+ NULL,
+ &error);
+
+ if (manager_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(manager_proxy, "activated",
+ G_CALLBACK(manager_activated), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_manager_deinit(void)
+{
+ if (manager_proxy)
+ {
+ g_object_unref(manager_proxy);
+ manager_proxy = NULL;
+ }
+
+ if (activated_func_data)
+ {
+ g_free(activated_func_data);
+ activated_func_data = NULL;
+ }
+}
+
+/* internal function */
+bool net_nfc_client_manager_is_activated()
+{
+ if (is_activated < 0) {
+ net_nfc_client_get_nfc_state(&is_activated);
+ }
+
+ return is_activated;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_data.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_ndef.h"
+#include "net_nfc_client_tag_internal.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+typedef struct _NdefFuncData NdefFuncData;
+
+struct _NdefFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusNdef *ndef_proxy = NULL;
+
+static ndef_message_h ndef_variant_to_message(GVariant *variant);
+
+static GVariant *ndef_message_to_variant(ndef_message_h message);
+
+static gboolean ndef_is_supported_tag(void);
+
+static void ndef_call_read(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void ndef_call_write(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void ndef_call_make_read_only(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void ndef_call_format(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static ndef_message_h ndef_variant_to_message(GVariant *variant)
+{
+ data_s data;
+ ndef_message_h message = NULL;
+
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+
+ if (data.buffer && data.length > 0)
+ {
+ if (net_nfc_create_ndef_message_from_rawdata(&message, &data)
+ != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("memory alloc fail...");
+ }
+
+ net_nfc_util_free_data(&data);
+ }
+
+ return message;
+}
+
+static GVariant *ndef_message_to_variant(ndef_message_h message)
+{
+ guint length;
+ data_s data;
+ GVariant *variant = NULL;
+
+ length = net_nfc_util_get_ndef_message_length(
+ (ndef_message_s *)message);
+
+ if (length == 0)
+ {
+ DEBUG_ERR_MSG("message length is 0");
+ return NULL;
+ }
+
+ data.length = length;
+ data.buffer = g_new0(guint8, length);
+
+ if(net_nfc_util_convert_ndef_message_to_rawdata(
+ (ndef_message_s *)message,
+ &data) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("can not convert ndef_message to rawdata");
+ return NULL;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(&data);
+
+ g_free(data.buffer);
+
+ return variant;
+}
+
+static gboolean ndef_is_supported_tag(void)
+{
+ net_nfc_target_info_s *target_info = NULL;
+
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ {
+ DEBUG_ERR_MSG("target_info does not exist");
+ return TRUE;
+ }
+
+ switch (target_info->devType)
+ {
+ case NET_NFC_ISO14443_A_PICC :
+ case NET_NFC_MIFARE_MINI_PICC :
+ case NET_NFC_MIFARE_1K_PICC :
+ case NET_NFC_MIFARE_4K_PICC :
+ case NET_NFC_MIFARE_ULTRA_PICC :
+ case NET_NFC_JEWEL_PICC :
+ return TRUE;
+ break;
+ default:
+ DEBUG_CLIENT_MSG(
+ "not supported tag for read only tag");
+ return FALSE;
+ }
+}
+
+static void ndef_call_read(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NdefFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_ndef_read_completed callback;
+
+ GVariant *out_data = NULL;
+ ndef_message_h message = NULL;
+
+ if (net_nfc_gdbus_ndef_call_read_finish(
+ NET_NFC_GDBUS_NDEF(source_object),
+ (gint *)&out_result,
+ &out_data,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish read: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (NdefFuncData *)user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get NdefFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ if (out_result == NET_NFC_OK)
+ message = ndef_variant_to_message(out_data);
+
+ callback = (net_nfc_client_ndef_read_completed)func_data->callback;
+ callback(out_result, message, func_data->user_data);
+
+ if (message)
+ net_nfc_util_free_ndef_message(message);
+
+ g_free(func_data);
+}
+
+static void ndef_call_write(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NdefFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_ndef_write_completed callback;
+
+ if (net_nfc_gdbus_ndef_call_write_finish(
+ NET_NFC_GDBUS_NDEF(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish write: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (NdefFuncData *)user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get NdefFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_ndef_write_completed)func_data->callback;
+ callback(out_result, func_data->user_data);
+
+ g_free(func_data);
+}
+
+static void ndef_call_make_read_only(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NdefFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_ndef_make_read_only_completed callback;
+
+ if (net_nfc_gdbus_ndef_call_make_read_only_finish(
+ NET_NFC_GDBUS_NDEF(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish make read only: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = (NdefFuncData *)user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get NdefFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_ndef_make_read_only_completed)
+ func_data->callback;
+ callback(out_result, func_data->user_data);
+
+ g_free(func_data);
+}
+
+static void ndef_call_format(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NdefFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_ndef_format_completed callback;
+
+ if (net_nfc_gdbus_ndef_call_format_finish(
+ NET_NFC_GDBUS_NDEF(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish format: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (NdefFuncData *)user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get NdefFuncData");
+ return;
+ }
+
+ if (func_data->callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_ndef_format_completed) func_data->callback;
+ callback(out_result, func_data->user_data);
+
+ g_free(func_data);
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_ndef_read(net_nfc_target_handle_h handle,
+ net_nfc_client_ndef_read_completed callback,
+ void *user_data)
+{
+ NdefFuncData *func_data;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle);
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ func_data = g_new0(NdefFuncData, 1);
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_ndef_call_read(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ ndef_call_read,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_ndef_read_sync(net_nfc_target_handle_h handle,
+ ndef_message_h *message)
+{
+ GVariant *out_data = NULL;
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle);
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ if (net_nfc_gdbus_ndef_call_read_sync(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ &out_data,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call read: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ *message = ndef_variant_to_message(out_data);
+
+ return out_result;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_ndef_write(net_nfc_target_handle_h handle,
+ ndef_message_h message,
+ net_nfc_client_ndef_write_completed callback,
+ void *user_data)
+{
+ NdefFuncData *func_data;
+
+ GVariant *arg_data = NULL;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (message == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ func_data = g_new0(NdefFuncData, 1);
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ arg_data = ndef_message_to_variant(message);
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ net_nfc_gdbus_ndef_call_write(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ ndef_call_write,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_ndef_write_sync(net_nfc_target_handle_h handle,
+ ndef_message_h message)
+{
+ GVariant *arg_data = NULL;
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (message == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = ndef_message_to_variant(message);
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ if (net_nfc_gdbus_ndef_call_write_sync(ndef_proxy ,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call write: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_ndef_make_read_only(
+ net_nfc_target_handle_h handle,
+ net_nfc_client_ndef_make_read_only_completed callback,
+ void *user_data)
+{
+ NdefFuncData *func_data;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ if (ndef_is_supported_tag() == FALSE)
+ return NET_NFC_NOT_SUPPORTED;
+
+ func_data = g_new0(NdefFuncData, 1);
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_ndef_call_make_read_only(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ ndef_call_make_read_only,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_ndef_make_read_only_sync(
+ net_nfc_target_handle_h handle)
+{
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ if (ndef_is_supported_tag() == FALSE)
+ return NET_NFC_NOT_SUPPORTED;
+
+ if (net_nfc_gdbus_ndef_call_make_read_only_sync(ndef_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not make read only: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle,
+ data_h key,
+ net_nfc_client_ndef_format_completed callback,
+ void *user_data)
+{
+ NdefFuncData *func_data;
+ GVariant *arg_data = NULL;
+
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (key == NULL)
+ arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ else
+ {
+ data_s *key_s;
+
+ key_s = (data_s *)key;
+ arg_data = net_nfc_util_gdbus_data_to_variant(key_s);
+ }
+
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ func_data = g_new0(NdefFuncData, 1);
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_ndef_call_format(ndef_proxy ,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ ndef_call_format,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_ndef_format_sync(
+ net_nfc_target_handle_h handle,
+ data_h key)
+{
+ GVariant *arg_data = NULL;
+ GError *error = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get NdefProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (key == NULL)
+ arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ else
+ {
+ data_s *key_s;
+
+ key_s = (data_s *)key;
+ arg_data = net_nfc_util_gdbus_data_to_variant(key_s);
+ }
+
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ if (net_nfc_gdbus_ndef_call_format_sync(ndef_proxy ,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not call format: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+net_nfc_error_e net_nfc_client_ndef_init(void)
+{
+ GError *error = NULL;
+
+ if (ndef_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+ return NET_NFC_OK;
+ }
+
+ ndef_proxy = net_nfc_gdbus_ndef_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Ndef",
+ NULL,
+ &error);
+
+ if (ndef_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_ndef_deinit(void)
+{
+ if (ndef_proxy)
+ {
+ g_object_unref(ndef_proxy);
+ ndef_proxy = NULL;
+ }
+}
* limitations under the License.
*/
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_ndef_message.h"
-
#include "net_nfc_ndef_message.h"
-#include "net_nfc.h" // to use net_nfc_data
+#include "net_nfc_data.h"
+
#ifndef NET_NFC_MANAGER_DATA_PATH
-#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon"
+#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon"
#endif
#ifndef NET_NFC_MANAGER_DATA_PATH_MESSAGE
/* public functions */
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message (ndef_message_h* ndef_message)
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message(ndef_message_h *ndef_message)
{
- return net_nfc_util_create_ndef_message ((ndef_message_s **) ndef_message);
+ return net_nfc_util_create_ndef_message((ndef_message_s **)ndef_message);
}
-
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message (ndef_message_h ndef_message, data_h* rawdata)
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message(ndef_message_h ndef_message, data_h *rawdata)
{
- if (ndef_message == NULL || rawdata == NULL){
+ uint32_t count;
+ net_nfc_error_e result;
+ data_h data;
+
+ if (ndef_message == NULL || rawdata == NULL) {
return NET_NFC_NULL_PARAMETER;
}
- int count;
- net_nfc_error_e result;
- result = net_nfc_get_ndef_message_byte_length (ndef_message,&count);
- if (result != NET_NFC_OK){
+ *rawdata = NULL;
+
+ result = net_nfc_get_ndef_message_byte_length(ndef_message, &count);
+ if (result != NET_NFC_OK) {
return result;
}
- result = net_nfc_create_data (rawdata ,NULL, count);
+ result = net_nfc_create_data(&data ,NULL, count);
if (result != NET_NFC_OK) {
return result;
}
- return net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s*)ndef_message, (data_s*)*rawdata);
+
+ result = net_nfc_util_convert_ndef_message_to_rawdata(
+ (ndef_message_s *)ndef_message, (data_s *)data);
+ if (result == NET_NFC_OK) {
+ *rawdata = data;
+ } else {
+ net_nfc_free_data(data);
+ }
+
+ return result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message_from_rawdata (ndef_message_h* ndef_message, data_h rawdata)
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_ndef_message_from_rawdata(ndef_message_h *ndef_message, data_h rawdata)
{
- if (ndef_message == NULL || rawdata == NULL ){
+ net_nfc_error_e result;
+ ndef_message_h msg;
+
+ if (ndef_message == NULL || rawdata == NULL) {
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_error_e result;
- result = net_nfc_create_ndef_message (ndef_message);
- if (result != NET_NFC_OK){
+ *ndef_message = NULL;
+
+ result = net_nfc_create_ndef_message(&msg);
+ if (result != NET_NFC_OK) {
return result;
}
- return net_nfc_util_convert_rawdata_to_ndef_message((data_s*)rawdata, (ndef_message_s*)*ndef_message);
-}
+ result = net_nfc_util_convert_rawdata_to_ndef_message(
+ (data_s *)rawdata, (ndef_message_s *)msg);
+ if (result == NET_NFC_OK) {
+ *ndef_message = msg;
+ } else {
+ net_nfc_free_ndef_message(msg);
+ }
+ return result;
+}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, int * length)
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, uint32_t *length)
{
+ net_nfc_error_e result;
+
if (ndef_message == NULL || length == NULL){
return NET_NFC_NULL_PARAMETER;
}
- * length = net_nfc_util_get_ndef_message_length((ndef_message_s*)ndef_message);
- return NET_NFC_OK;
+ *length = net_nfc_util_get_ndef_message_length((ndef_message_s *)ndef_message);
+ if (*length > 0) {
+ result = NET_NFC_OK;
+ } else {
+ result = NET_NFC_INVALID_PARAM;
+ }
+
+ return result;
}
NET_NFC_EXPORT_API net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record)
NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message)
{
- if (ndef_message == NULL){
+ if (ndef_message == NULL) {
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_error_e error = net_nfc_util_free_ndef_message((ndef_message_s *)ndef_message);
- if (error != NET_NFC_OK){
- return error;
- }
- return error;
+
+ return net_nfc_util_free_ndef_message((ndef_message_s *)ndef_message);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_record_count (ndef_message_h ndef_message, int * count)
+NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_ndef_message_record_count(ndef_message_h ndef_message, int *count)
{
- if (ndef_message == NULL || count == NULL){
+ if (ndef_message == NULL || count == NULL) {
return NET_NFC_NULL_PARAMETER;
}
- ndef_message_s * ndef_message_private = (ndef_message_s *)ndef_message;
- * count = ndef_message_private->recordCount;
+ ndef_message_s *msg = (ndef_message_s *)ndef_message;
+
+ *count = msg->recordCount;
return NET_NFC_OK;
}
#include "net_nfc_ndef_message_handover.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_handover.h"
#ifndef NET_NFC_EXPORT_API
#include "net_nfc_ndef_record.h"
#include "net_nfc_ndef_message.h"
#include "net_nfc_data.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_ndef_record.h"
#ifndef NET_NFC_EXPORT_API
NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_record_id(ndef_record_h record, data_h id)
{
- ndef_record_s * record_private = (ndef_record_s *)record;
- data_s * id_private = (data_s *)id;
+ ndef_record_s * tmp_record = (ndef_record_s *)record;
+ data_s * tmp_id = (data_s *)id;
- if (id_private == NULL)
+ if (tmp_id == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- return net_nfc_util_set_record_id(record_private, id_private->buffer, id_private->length);
+ return net_nfc_util_set_record_id(tmp_record, tmp_id->buffer, tmp_id->length);
}
NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_record_flags(ndef_record_h record, uint8_t * flag)
NET_NFC_EXPORT_API uint8_t net_nfc_get_record_mb(uint8_t flag)
{
- return (flag & 0x80) >> 7;
+ return ((flag >> 7) & 0x01);
}
NET_NFC_EXPORT_API uint8_t net_nfc_get_record_me(uint8_t flag)
{
- return (flag & 0x40) >> 6;
+ return ((flag >> 6) & 0x01);
}
NET_NFC_EXPORT_API uint8_t net_nfc_get_record_cf(uint8_t flag)
{
- return (flag & 0x20) >> 5;
+ return ((flag >> 5) & 0x01);
}
-NET_NFC_EXPORT_API uint8_t net_nfc_get_record_il(uint8_t flag)
+NET_NFC_EXPORT_API uint8_t net_nfc_get_record_sr(uint8_t flag)
{
- return (flag & 0x10) >> 4;
+ return ((flag >> 4) & 0x01);
}
-NET_NFC_EXPORT_API uint8_t net_nfc_get_record_sr(uint8_t flag)
+NET_NFC_EXPORT_API uint8_t net_nfc_get_record_il(uint8_t flag)
{
- return (flag & 0x08) >> 3;
+ return ((flag >> 3) & 0x01);
}
NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer)
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <unistd.h>
-#include <pthread.h>
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "vconf.h"
-#ifdef SECURITY_SERVER
-#include <security-server.h>
-#endif
-
-#include "net_nfc.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_client_ipc_private.h"
-#include "net_nfc_exchanger_private.h"
-#include "net_nfc_client_nfc_private.h"
-#include "net_nfc_manager_dbus.h"
-#include "nfc-service-glue.h"
-
-#ifndef NET_NFC_EXPORT_API
-#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
-#endif
-
-#define BUFFER_LENGTH_MAX 1024
-
-static client_context_t g_client_context = { NULL, NET_NFC_OK, PTHREAD_MUTEX_INITIALIZER, NET_NFC_ALL_ENABLE, NULL, false };
-
-static void _net_nfc_reset_client_context()
-{
- g_client_context.register_user_param = NULL;
- g_client_context.result = NET_NFC_OK;
- g_client_context.filter = NET_NFC_ALL_ENABLE;
- g_client_context.initialized = false;
-}
-
-static net_nfc_error_e _net_nfc_launch_daemon()
-{
- net_nfc_error_e result = NET_NFC_OPERATION_FAIL;
- DBusGConnection *connection = NULL;
- GError *error = NULL;
-
- dbus_g_thread_init();
-
- connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (error == NULL)
- {
- DBusGProxy *proxy = NULL;
-
- proxy = dbus_g_proxy_new_for_name(connection, "org.tizen.nfc_service", "/org/tizen/nfc_service", "org.tizen.nfc_service");
- if (proxy != NULL)
- {
- guint dbus_result = 0;
-
- if (org_tizen_nfc_service_launch(proxy, getpid(), &dbus_result, &error) == true)
- {
- DEBUG_CLIENT_MSG("org_tizen_nfc_service_launch success");
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("org_tizen_nfc_service_launch failed");
- if (error != NULL)
- {
- DEBUG_ERR_MSG("message : [%s]", error->message);
- g_error_free(error);
- }
- }
-
- g_object_unref(proxy);
- }
- else
- {
- DEBUG_ERR_MSG("dbus_g_proxy_new_for_name failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("dbus_g_bus_get failed");
- if (error != NULL)
- {
- DEBUG_ERR_MSG("message : [%s]", error->message);
- g_error_free(error);
- }
- }
-
- return result;
-}
-
-#if 0
-static net_nfc_error_e _net_nfc_terminate_daemon()
-{
- net_nfc_error_e result = NET_NFC_OPERATION_FAIL;
- DBusGConnection *connection = NULL;
- GError *error = NULL;
-
- connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (error == NULL)
- {
- DBusGProxy *proxy = NULL;
-
- proxy = dbus_g_proxy_new_for_name(connection, "org.tizen.nfc_service", "/org/tizen/nfc_service", "org.tizen.nfc_service");
- if (proxy != NULL)
- {
- guint dbus_result = 0;
-
- if (org_tizen_nfc_service_terminate(proxy, &dbus_result, &error) == true)
- {
- DEBUG_CLIENT_MSG("org_tizen_nfc_service_terminate success");
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("org_tizen_nfc_service_terminate failed");
- if (error != NULL)
- {
- DEBUG_ERR_MSG("message : [%s]", error->message);
- g_error_free(error);
- }
- }
-
- g_object_unref (proxy);
- }
- else
- {
- DEBUG_ERR_MSG("dbus_g_proxy_new_for_name failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("dbus_g_bus_get failed, message : [%s]", error->message);
- g_error_free(error);
- }
-
- return result;
-}
-#endif
-
-#ifdef SECURITY_SERVER
-static net_nfc_error_e _net_nfc_load_cookies()
-{
- net_nfc_error_e result = NET_NFC_OK;
- int cookies_size;
- char cookies[512] = { 0, };
-
- if ((cookies_size = security_server_get_cookie_size()) > 0)
- {
- int error = 0;
-
- if ((error = security_server_request_cookie(cookies, cookies_size)) == SECURITY_SERVER_API_SUCCESS)
- {
-#if 0
- DEBUG_SERVER_MSG("load cookies");
- DEBUG_MSG_PRINT_BUFFER(cookies, cookies_size);
-#endif
-
- _net_nfc_client_set_cookies(cookies, cookies_size);
-
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("security server request cookies error = [%d]", error);
-
- result = NET_NFC_SECURITY_FAIL;
- }
- }
- else
- {
- DEBUG_ERR_MSG("wrong cookie length");
-
- result = NET_NFC_SECURITY_FAIL;
- }
-
- return result;
-}
-#endif
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_initialize()
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- if (!g_thread_supported())
- {
- g_thread_init(NULL);
- }
-
- g_type_init();
-
- pthread_mutex_lock(&g_client_context.g_client_lock);
-
- if (g_client_context.initialized == true)
- {
- pthread_mutex_unlock(&g_client_context.g_client_lock);
- return result;
- }
-
- result = _net_nfc_launch_daemon();
- if (result != NET_NFC_OK)
- {
- pthread_mutex_unlock(&g_client_context.g_client_lock);
- return result;
- }
-
- _net_nfc_reset_client_context();
-
-#ifdef SECURITY_SERVER
- result = _net_nfc_load_cookies();
- if (result != NET_NFC_OK)
- {
- pthread_mutex_unlock(&g_client_context.g_client_lock);
- return result;
- }
-#endif
-
- result = net_nfc_client_socket_initialize();
- if (result == NET_NFC_OK || result == NET_NFC_ALREADY_INITIALIZED)
- {
- DEBUG_CLIENT_MSG("socket is initialized");
- g_client_context.initialized = true;
- }
- else
- {
- DEBUG_ERR_MSG("socket init is failed = [%d]", result);
- _net_nfc_client_free_cookies();
- }
-
- pthread_mutex_unlock(&g_client_context.g_client_lock);
-
- return result;
-}
-
-/* this is sync call */
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_deinitialize()
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- pthread_mutex_lock(&g_client_context.g_client_lock);
-
- net_nfc_client_socket_finalize();
- _net_nfc_client_free_cookies();
- _net_nfc_reset_client_context();
-
-#if 0
- result = _net_nfc_terminate_daemon();
-#endif
-
- pthread_mutex_unlock(&g_client_context.g_client_lock);
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_response_callback(net_nfc_response_cb cb, void *user_param)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- if (cb == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- pthread_mutex_lock(&g_client_context.g_client_lock);
-
- g_client_context.register_user_param = user_param;
- result = _net_nfc_client_register_cb(cb);
-
- pthread_mutex_unlock(&g_client_context.g_client_lock);
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_response_callback(void)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- pthread_mutex_lock(&g_client_context.g_client_lock);
-
- g_client_context.register_user_param = NULL;
- result = _net_nfc_client_unregister_cb();
-
- pthread_mutex_unlock(&g_client_context.g_client_lock);
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_launch_popup_state(int enable)
-{
- net_nfc_error_e ret;
- net_nfc_request_set_launch_state_t request = { 0, };
-
- request.length = sizeof(net_nfc_request_set_launch_state_t);
- request.request_type = NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE;
-
- pthread_mutex_lock(&g_client_context.g_client_lock);
- g_client_context.set_launch_popup = enable;
-
- if(enable)
- request.set_launch_popup = NET_NFC_LAUNCH_APP_SELECT;
- else
- request.set_launch_popup = NET_NFC_NO_LAUNCH_APP_SELECT;
-
- pthread_mutex_unlock(&g_client_context.g_client_lock);
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_launch_popup_state(int *state)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- if (state == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- pthread_mutex_lock(&g_client_context.g_client_lock);
- *state = g_client_context.set_launch_popup;
- pthread_mutex_unlock(&g_client_context.g_client_lock);
-
- return result;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_state(int state, net_nfc_set_activation_completed_cb callback)
-{
- net_nfc_error_e ret = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_CLIENT_MSG("net_nfc_set_state[Enter]");
-
-#if 0
- if (!g_thread_supported())
- {
- g_thread_init(NULL);
- }
-
- g_type_init();
-#endif
-
- if (state == FALSE)/*Deinit*/
- {
- ret = net_nfc_send_deinit(NULL);
-
- DEBUG_CLIENT_MSG("Send the deinit msg!!, result [%d]", ret);
- }
- else/*INIT*/
- {
- ret = net_nfc_send_init(NULL);
-
- DEBUG_CLIENT_MSG("Send the init msg!!, result [%d]", ret);
- }
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_supported(int *state)
-{
- net_nfc_error_e ret;
-
- if (state != NULL)
- {
- if (vconf_get_bool(VCONFKEY_NFC_FEATURE, state) == 0)
- {
- ret = NET_NFC_OK;
- }
- else
- {
- ret = NET_NFC_INVALID_STATE;
- }
- }
- else
- {
- ret = NET_NFC_NULL_PARAMETER;
- }
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_state(int *state)
-{
- net_nfc_error_e ret;
-
- if (state != NULL)
- {
- if (vconf_get_bool(VCONFKEY_NFC_STATE, state) == 0)
- {
- ret = NET_NFC_OK;
- }
- else
- {
- ret = NET_NFC_INVALID_STATE;
- }
- }
- else
- {
- ret = NET_NFC_NULL_PARAMETER;
- }
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_state_activate(void)
-{
- net_nfc_error_e ret;
- net_nfc_request_change_client_state_t request = { 0, };
-
- request.length = sizeof(net_nfc_request_change_client_state_t);
- request.request_type = NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE;
- request.client_state = NET_NFC_CLIENT_ACTIVE_STATE;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
-}
-
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_state_deactivate(void)
-{
- net_nfc_error_e ret;
- net_nfc_request_change_client_state_t request = { 0, };
-
- request.length = sizeof(net_nfc_request_change_client_state_t);
- request.request_type = NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE;
- request.client_state = NET_NFC_CLIENT_INACTIVE_STATE;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
-
- return ret;
-}
-
-client_context_t *net_nfc_get_client_context()
-{
- return &g_client_context;
-}
-
-bool net_nfc_tag_is_connected()
-{
- bool result = false;
-
- pthread_mutex_lock(&g_client_context.g_client_lock);
-
- result = (g_client_context.target_info != NULL && g_client_context.target_info->handle != NULL);
-
- pthread_mutex_unlock(&g_client_context.g_client_lock);
-
- return result;
-}
-
-net_nfc_error_e net_nfc_send_init(void *context)
-{
- net_nfc_error_e ret;
- net_nfc_request_msg_t req_msg = { 0, };
-
- req_msg.length = sizeof(net_nfc_request_msg_t);
- req_msg.request_type = NET_NFC_MESSAGE_SERVICE_INIT;
- req_msg.user_param = (uint32_t)context;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&req_msg, NULL);
-
- return ret;
-}
-
-net_nfc_error_e net_nfc_send_deinit(void *context)
-{
- net_nfc_error_e ret;
- net_nfc_request_msg_t req_msg = { 0, };
-
- req_msg.length = sizeof(net_nfc_request_msg_t);
- req_msg.request_type = NET_NFC_MESSAGE_SERVICE_DEINIT;
- req_msg.user_param = (uint32_t)context;
-
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&req_msg, NULL);
-
- return ret;
-}
-
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_p2p.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+typedef struct _P2pFuncData P2pFuncData;
+
+struct _P2pFuncData
+{
+ gpointer p2p_send_callback;
+ gpointer p2p_send_data;
+};
+
+
+typedef struct _P2p_SignalHandler P2pSignalHandler;
+
+struct _P2p_SignalHandler
+{
+ net_nfc_client_p2p_device_discovered p2p_device_discovered_cb;
+ net_nfc_client_p2p_device_detached p2p_device_detached_cb;
+ net_nfc_client_p2p_data_received p2p_data_received_cb;
+
+ gpointer p2p_device_discovered_data;
+ gpointer p2p_device_detached_data;
+ gpointer p2p_data_received_data;
+};
+
+static NetNfcGDbusP2p *p2p_proxy = NULL;
+static P2pSignalHandler *p2p_signal_handler = NULL;
+
+static void p2p_device_detached(GObject *source_object,
+ gpointer user_data);
+
+static void p2p_device_discovered(GObject *source_object,
+ guint arg_handle,
+ gpointer user_data);
+
+static void p2p_device_data_received(GObject *source_object,
+ GVariant *arg_data,
+ gpointer user_data);
+
+static void p2p_call_send(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void p2p_device_detached(GObject *source_object,
+ gpointer user_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ /*llcp client function to set/unset the current target id needs to be implemented*/
+ /*net_nfc_client_llcp_current_target_id(NULL);*/
+
+ if(p2p_signal_handler == NULL)
+ return;
+
+ if(p2p_signal_handler->p2p_device_detached_cb)
+ {
+ p2p_signal_handler->p2p_device_detached_cb(
+ p2p_signal_handler->p2p_device_detached_data);
+ }
+
+ /*llcp client function to close all socket needs to be implemented*/
+ /*net_nfc_client_llcp_close_all_socket();*/
+}
+
+static void p2p_device_discovered(GObject *source_object,
+ guint arg_handle,
+ gpointer user_data)
+{
+ net_nfc_target_handle_s *handle_info = NULL;
+
+ INFO_MSG(">>> SIGNAL arrived");
+
+ handle_info = GUINT_TO_POINTER(arg_handle);
+
+ if(p2p_signal_handler == NULL)
+ return;
+
+ if(p2p_signal_handler->p2p_device_discovered_cb)
+ {
+ p2p_signal_handler->p2p_device_discovered_cb(handle_info,
+ p2p_signal_handler->p2p_device_discovered_data);
+ }
+}
+
+static void p2p_device_data_received(GObject *source_object,
+ GVariant *arg_data,
+ gpointer user_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (p2p_signal_handler == NULL)
+ return;
+
+ if (p2p_signal_handler->p2p_data_received_cb)
+ {
+ data_s p2p_data;
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &p2p_data);
+
+ p2p_signal_handler->p2p_data_received_cb(&p2p_data,
+ p2p_signal_handler->p2p_data_received_data);
+
+ net_nfc_util_free_data(&p2p_data);
+ }
+}
+
+static void p2p_call_send(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ P2pFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_p2p_send_completed callback;
+
+ if (net_nfc_gdbus_p2p_call_send_finish(
+ NET_NFC_GDBUS_P2P(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish p2p send: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get P2pFuncData");
+ return;
+ }
+
+ if (func_data->p2p_send_callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_p2p_send_completed)
+ func_data->p2p_send_callback;
+ callback(out_result, func_data->p2p_send_data);
+
+ g_free(func_data);
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_p2p_send(net_nfc_exchanger_data_h exchg_data,
+ net_nfc_target_handle_h handle,
+ net_nfc_client_p2p_send_completed callback,
+ void *cb_data)
+{
+
+ GVariant *arg_data = NULL;
+ P2pFuncData *func_data = NULL;
+ net_nfc_exchanger_data_s *exch_data;
+
+ if(p2p_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get P2pProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(P2pFuncData, 1);
+
+ func_data->p2p_send_callback = (gpointer)callback;
+ func_data->p2p_send_data = cb_data;
+
+ exch_data = (net_nfc_exchanger_data_s *)exchg_data;
+
+ arg_data = net_nfc_util_gdbus_data_to_variant(&exch_data->binary_data);
+
+ net_nfc_gdbus_p2p_call_send(p2p_proxy,
+ exch_data->type,
+ arg_data,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ p2p_call_send,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_p2p_send_sync(
+ net_nfc_exchanger_data_h exchg_data,
+ net_nfc_target_handle_h handle)
+{
+ GVariant *arg_data = NULL;
+ GError *error = NULL;
+ net_nfc_exchanger_data_s *exch_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (p2p_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get P2pProxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ exch_data = (net_nfc_exchanger_data_s *)exchg_data;
+
+ arg_data = net_nfc_util_gdbus_data_to_variant(&exch_data->binary_data);
+
+ if (net_nfc_gdbus_p2p_call_send_sync(p2p_proxy,
+ exch_data->type,
+ arg_data,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("p2p send (sync call) failed: %s",
+ error->message);
+
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_p2p_set_device_discovered(
+ net_nfc_client_p2p_device_discovered callback,
+ void *user_data)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ p2p_signal_handler = g_new0(P2pSignalHandler, 1);
+ }
+
+ p2p_signal_handler->p2p_device_discovered_cb = callback;
+ p2p_signal_handler->p2p_device_discovered_data = user_data;
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_p2p_set_device_detached(
+ net_nfc_client_p2p_device_detached callback,
+ void *user_data)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ p2p_signal_handler = g_new0(P2pSignalHandler, 1);
+ }
+
+ p2p_signal_handler->p2p_device_detached_cb = callback;
+ p2p_signal_handler->p2p_device_detached_data = user_data;
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_p2p_set_data_received(
+ net_nfc_client_p2p_data_received callback,
+ void *user_data)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ p2p_signal_handler = g_new0(P2pSignalHandler, 1);
+ }
+
+ p2p_signal_handler->p2p_data_received_cb = callback;
+ p2p_signal_handler->p2p_data_received_data = user_data;
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_p2p_unset_device_discovered(void)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
+ return;
+ }
+
+ else
+ {
+ p2p_signal_handler->p2p_device_discovered_cb = NULL;
+ p2p_signal_handler->p2p_device_discovered_data = NULL;
+ g_free(p2p_signal_handler);
+ p2p_signal_handler = NULL;
+ }
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_p2p_unset_device_detached(void)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
+ return;
+ }
+
+ else
+ {
+ p2p_signal_handler->p2p_device_detached_cb = NULL;
+ p2p_signal_handler->p2p_device_detached_data = NULL;
+ }
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_p2p_unset_data_received(void)
+{
+ if(p2p_signal_handler == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_signal_handler is not initialized");
+ return;
+ }
+
+ else
+ {
+ p2p_signal_handler->p2p_data_received_cb = NULL;
+ p2p_signal_handler->p2p_data_received_data = NULL;
+ }
+}
+
+net_nfc_error_e net_nfc_client_p2p_init(void)
+{
+ GError *error = NULL;
+
+ if (p2p_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ p2p_proxy = net_nfc_gdbus_p2p_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/P2p",
+ NULL,
+ &error);
+ if (p2p_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(p2p_proxy, "detached",
+ G_CALLBACK(p2p_device_detached), NULL);
+
+ g_signal_connect(p2p_proxy, "discovered",
+ G_CALLBACK(p2p_device_discovered), NULL);
+
+ g_signal_connect(p2p_proxy, "received",
+ G_CALLBACK(p2p_device_data_received), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_p2p_deinit(void)
+{
+ if(p2p_proxy)
+ {
+ g_object_unref(p2p_proxy);
+ p2p_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_se.h"
+
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+typedef struct _SeFuncData SeFuncData;
+
+struct _SeFuncData
+{
+ gpointer se_callback;
+ gpointer se_data;
+};
+
+typedef struct _SeEventHandler SeEventHandler;
+
+struct _SeEventHandler
+{
+ net_nfc_client_se_event se_event_cb;
+ gpointer se_event_data;
+};
+
+typedef struct _SeTransEventHandler SeTransEventHandler;
+
+struct _SeTransEventHandler
+{
+ net_nfc_client_se_transaction_event se_transaction_event_cb;
+ gpointer se_transaction_event_data;
+};
+
+typedef struct _SeESEDetectedHandler SeESEDetectedHandler;
+
+struct _SeESEDetectedHandler
+{
+ net_nfc_client_se_ese_detected_event se_ese_detected_cb;
+ gpointer se_ese_detected_data;
+};
+
+
+static NetNfcGDbusSecureElement *se_proxy = NULL;
+
+static SeEventHandler se_eventhandler;
+static SeTransEventHandler se_transeventhandler;
+static SeESEDetectedHandler se_esedetecthandler;
+
+static void se_ese_detected(GObject *source_object,
+ guint arg_handle,
+ gint arg_se_type,
+ GVariant *arg_data);
+
+static void se_type_changed(GObject *source_object,
+ gint arg_se_type);
+
+static void set_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void open_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void close_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void send_apdu_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void get_atr_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+
+static void se_ese_detected(GObject *source_object,
+ guint arg_handle,
+ gint arg_se_type,
+ GVariant *arg_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (se_esedetecthandler.se_ese_detected_cb != NULL) {
+ data_s buffer_data = { NULL, 0 };
+ net_nfc_client_se_ese_detected_event callback =
+ (net_nfc_client_se_ese_detected_event)se_esedetecthandler.se_ese_detected_cb;
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &buffer_data);
+
+ callback((net_nfc_target_handle_h)arg_handle,
+ arg_se_type, &buffer_data,
+ se_esedetecthandler.se_ese_detected_data);
+
+ net_nfc_util_free_data(&buffer_data);
+ }
+}
+
+
+static void se_type_changed(GObject *source_object,
+ gint arg_se_type)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (se_eventhandler.se_event_cb != NULL)
+ {
+ net_nfc_client_se_event callback =
+ (net_nfc_client_se_event)se_eventhandler.se_event_cb;
+
+ callback((net_nfc_message_e)arg_se_type,
+ se_eventhandler.se_event_data);
+ }
+}
+
+
+static void se_transaction_event(GObject *source_object,
+ gint arg_se_type,
+ GVariant *arg_aid,
+ GVariant *arg_param)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+
+ if (se_transeventhandler.se_transaction_event_cb != NULL) {
+ net_nfc_client_se_transaction_event callback =
+ (net_nfc_client_se_transaction_event)se_transeventhandler.se_transaction_event_cb;
+ data_s aid = { NULL, 0 };
+ data_s param = { NULL, 0 };
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_aid, &aid);
+ net_nfc_util_gdbus_variant_to_data_s(arg_param, ¶m);
+
+ callback(&aid, ¶m,
+ se_transeventhandler.se_transaction_event_data);
+
+ net_nfc_util_free_data(¶m);
+ net_nfc_util_free_data(&aid);
+ }
+}
+
+
+static void set_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_set_finish(se_proxy,
+ &result,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not set secure element: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_set_se_cb se_callback =
+ (net_nfc_se_set_se_cb)func_data->se_callback;
+
+ se_callback(result, func_data->se_data);
+ }
+
+ g_free(func_data);
+}
+
+
+static void open_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GError *error = NULL;
+ guint out_handle;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_open_secure_element_finish(
+ se_proxy,
+ &result,
+ &out_handle,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not open secure element: %s",
+ error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_open_se_cb se_callback =
+ (net_nfc_se_open_se_cb)func_data->se_callback;
+
+ se_callback(result,
+ (net_nfc_target_handle_h)out_handle,
+ func_data->se_data);
+ }
+
+ g_free(func_data);
+}
+
+
+static void close_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_close_secure_element_finish(
+ se_proxy,
+ &result,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not close secure element: %s", error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_close_se_cb se_callback =
+ (net_nfc_se_close_se_cb)func_data->se_callback;
+
+ se_callback(result, func_data->se_data);
+ }
+
+ g_free(func_data);
+}
+
+
+static void send_apdu_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GVariant *out_response;
+ GError *error = NULL;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_send_apdu_finish(
+ se_proxy,
+ &result,
+ &out_response,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not send apdu: %s", error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_send_apdu_cb se_callback =
+ (net_nfc_se_send_apdu_cb)func_data->se_callback;
+ data_s data = { NULL, };
+
+ net_nfc_util_gdbus_variant_to_data_s(out_response, &data);
+
+ se_callback(result, &data, func_data->se_data);
+
+ net_nfc_util_free_data(&data);
+ }
+
+ g_free(func_data);
+}
+
+
+static void get_atr_secure_element(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ SeFuncData *func_data = (SeFuncData *)user_data;
+ net_nfc_error_e result;
+ GVariant *out_atr;
+ GError *error = NULL;
+
+ g_assert(user_data != NULL);
+
+ if (net_nfc_gdbus_secure_element_call_get_atr_finish(
+ se_proxy,
+ &result,
+ &out_atr,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_IPC_FAIL;
+
+ DEBUG_ERR_MSG("Could not get atr: %s", error->message);
+
+ g_error_free(error);
+ }
+
+ if (func_data->se_callback != NULL)
+ {
+ net_nfc_se_get_atr_cb se_callback =
+ (net_nfc_se_get_atr_cb)func_data->se_callback;
+ data_s data = { NULL, };
+
+ net_nfc_util_gdbus_variant_to_data_s(out_atr, &data);
+
+ se_callback(result, &data, func_data->se_data);
+
+ net_nfc_util_free_data(&data);
+ }
+
+ g_free(func_data);
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_set_secure_element_type(
+ net_nfc_se_type_e se_type,
+ net_nfc_se_set_se_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_set(
+ se_proxy,
+ (gint)se_type,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ set_secure_element,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync(
+ net_nfc_se_type_e se_type)
+{
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_secure_element_call_set_sync(
+ se_proxy,
+ (gint)se_type,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Set secure element failed: %s", error->message);
+
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_open_internal_secure_element(
+ net_nfc_se_type_e se_type,
+ net_nfc_se_open_se_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_open_secure_element(
+ se_proxy,
+ (gint)se_type,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ open_secure_element,
+ user_data);
+
+ return NET_NFC_OK;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync(
+ net_nfc_se_type_e se_type,
+ net_nfc_target_handle_h *handle)
+{
+ net_nfc_error_e result;
+ guint out_handle;
+ GError *error = NULL;
+
+ if (handle == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ if (net_nfc_gdbus_secure_element_call_open_secure_element_sync(
+ se_proxy,
+ se_type,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ &out_handle,
+ NULL,
+ &error) == true) {
+ *handle = GUINT_TO_POINTER(out_handle);
+ } else {
+ DEBUG_ERR_MSG("Open internal secure element failed: %s",
+ error->message);
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_close_internal_secure_element(
+ net_nfc_target_handle_h handle,
+ net_nfc_se_close_se_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_close_secure_element(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ close_secure_element,
+ user_data);
+
+ return NET_NFC_OK;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync(
+ net_nfc_target_handle_h handle)
+{
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ if (net_nfc_gdbus_secure_element_call_close_secure_element_sync(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("close internal secure element failed: %s",
+ error->message);
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_get_atr(
+ net_nfc_target_handle_h handle,
+ net_nfc_se_get_atr_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_get_atr(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ get_atr_secure_element,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_get_atr_sync(
+ net_nfc_target_handle_h handle,
+ data_h *atr)
+{
+ net_nfc_error_e result;
+ GVariant *out_atr;
+ GError *error = NULL;
+
+ if (atr == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *atr = NULL;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ if (net_nfc_gdbus_secure_element_call_get_atr_sync(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ &out_atr,
+ NULL,
+ &error) == true) {
+ *atr = net_nfc_util_gdbus_variant_to_data(out_atr);
+ } else {
+ DEBUG_ERR_MSG("Get attributes failed: %s", error->message);
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_send_apdu(
+ net_nfc_target_handle_h handle,
+ data_h apdu_data,
+ net_nfc_se_send_apdu_cb callback,
+ void *user_data)
+{
+ SeFuncData *func_data;
+ GVariant *arg_data;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ func_data = g_new0(SeFuncData, 1);
+ if (func_data == NULL) {
+ g_variant_unref(arg_data);
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ func_data->se_callback = (gpointer)callback;
+ func_data->se_data = user_data;
+
+ net_nfc_gdbus_secure_element_call_send_apdu(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ send_apdu_secure_element,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_se_send_apdu_sync(
+ net_nfc_target_handle_h handle,
+ data_h apdu_data,
+ data_h *response)
+{
+ net_nfc_error_e result;
+ GVariant *out_data;
+ GVariant *arg_data;
+ GError *error = NULL;
+
+ if (response == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *response = NULL;
+
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get se_proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* allow this function even nfc is off */
+
+ arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)apdu_data);
+ if (arg_data == NULL)
+ return NET_NFC_INVALID_PARAM;
+
+ if (net_nfc_gdbus_secure_element_call_send_apdu_sync(
+ se_proxy,
+ GPOINTER_TO_UINT(handle),
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ &out_data,
+ NULL,
+ &error) == true) {
+ *response = net_nfc_util_gdbus_variant_to_data(out_data);
+ } else {
+ DEBUG_ERR_MSG("Send APDU failed: %s",
+ error->message);
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_se_set_ese_detection_cb(
+ net_nfc_client_se_ese_detected_event callback,
+ void *user_data)
+{
+ se_esedetecthandler.se_ese_detected_cb = callback;
+ se_esedetecthandler.se_ese_detected_data = user_data;
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_se_unset_ese_detection_cb(void)
+{
+ net_nfc_client_se_set_ese_detection_cb(NULL, NULL);
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_se_set_transaction_event_cb(
+ net_nfc_client_se_transaction_event callback,
+ void *user_data)
+{
+ se_transeventhandler.se_transaction_event_cb = callback;
+ se_transeventhandler.se_transaction_event_data = user_data;
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_se_unset_transaction_event_cb(void)
+{
+ net_nfc_client_se_set_transaction_event_cb(NULL, NULL);
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_se_set_event_cb(net_nfc_client_se_event callback,
+ void *user_data)
+{
+ se_eventhandler.se_event_cb = callback;
+ se_eventhandler.se_event_data = user_data;
+}
+
+
+NET_NFC_EXPORT_API
+void net_nfc_client_se_unset_event_cb(void)
+{
+ net_nfc_client_se_set_event_cb(NULL, NULL);
+}
+
+
+net_nfc_error_e net_nfc_client_se_init(void)
+{
+ GError *error = NULL;
+
+ if (se_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ se_proxy = net_nfc_gdbus_secure_element_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/SecureElement",
+ NULL,
+ &error);
+ if (se_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(se_proxy, "se-type-changed",
+ G_CALLBACK(se_type_changed), NULL);
+
+ g_signal_connect(se_proxy, "ese-detected",
+ G_CALLBACK(se_ese_detected), NULL);
+
+ g_signal_connect(se_proxy, "transaction-event",
+ G_CALLBACK(se_transaction_event), NULL);
+
+ return NET_NFC_OK;
+}
+
+
+void net_nfc_client_se_deinit(void)
+{
+ if (se_proxy)
+ {
+ g_object_unref(se_proxy);
+ se_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_data.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_snep.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+static NetNfcGDbusSnep *snep_proxy = NULL;
+
+/*******************************************************************/
+
+static GVariant *snep_message_to_variant(ndef_message_h message);
+
+static ndef_message_h snep_variant_to_message(GVariant *variant);
+
+/*********************************************************************/
+
+static void snep_send_client_request(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+/*********************************************************************/
+
+static GVariant *snep_message_to_variant(ndef_message_h message)
+{
+ data_h data = NULL;
+ GVariant *variant = NULL;
+
+ if (net_nfc_create_rawdata_from_ndef_message(message,
+ &data) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("can not convert ndef_message to rawdata");
+ return NULL;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
+
+ net_nfc_free_data(data);
+
+ return variant;
+}
+
+static ndef_message_h snep_variant_to_message(GVariant *variant)
+{
+ data_s data = { NULL, };
+ ndef_message_h message = NULL;
+
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+
+ if (data.buffer && data.length > 0)
+ {
+ if (net_nfc_create_ndef_message_from_rawdata(&message, &data)
+ != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("memory alloc fail...");
+ }
+
+ net_nfc_util_free_data(&data);
+ }
+
+ return message;
+}
+
+static void snep_send_client_request(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GVariant *parameter = (GVariant *)user_data;
+ GError *error = NULL;
+ net_nfc_error_e out_result;
+ net_nfc_snep_type_t out_type;
+ GVariant *out_data;
+
+ if (net_nfc_gdbus_snep_call_client_request_finish(
+ NET_NFC_GDBUS_SNEP(source_object),
+ (gint *)&out_result,
+ (guint *)&out_type,
+ &out_data,
+ res,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not finish send client request %s",
+ error->message);
+ g_error_free(error);
+
+ out_result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (parameter != NULL) {
+ net_nfc_client_snep_event_cb callback;
+ void *user_param;
+ net_nfc_snep_handle_h handle;
+ ndef_message_h message = NULL;
+
+ g_variant_get(parameter, "(uuu)",
+ (guint *)&callback,
+ (guint *)&user_param,
+ (guint *)&handle);
+
+ if (callback != NULL) {
+ message = snep_variant_to_message(out_data);
+
+ callback(handle, out_type, out_result,
+ message, user_param);
+ }
+
+ g_object_unref(parameter);
+ }
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_snep_start_server(
+ net_nfc_target_handle_h target,
+ const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+ GVariant *parameter;
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+
+ g_object_ref(parameter);
+
+ if (net_nfc_gdbus_snep_call_server_start_sync(snep_proxy,
+ GPOINTER_TO_UINT(target),
+ sap,
+ san,
+ GPOINTER_TO_UINT(parameter),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep server(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+ g_object_unref(parameter);
+
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return result;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_snep_start_client(
+ net_nfc_target_handle_h target,
+ const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+ GVariant *parameter;
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+
+ g_object_ref(parameter);
+
+ if (net_nfc_gdbus_snep_call_client_start_sync(snep_proxy,
+ GPOINTER_TO_UINT(target),
+ sap,
+ san,
+ GPOINTER_TO_UINT(parameter),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep client(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+ g_object_unref(parameter);
+
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return result;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_snep_send_client_request(
+ net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t snep_type,
+ ndef_message_h msg,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data)
+{
+ GVariant *ndef_msg = NULL;
+ GVariant *parameter;
+
+ if (target == NULL || msg == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ parameter = g_variant_new("(uuu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data),
+ GPOINTER_TO_UINT(target));
+
+ g_object_ref(parameter);
+
+ ndef_msg = snep_message_to_variant(msg);
+
+ net_nfc_gdbus_snep_call_client_request(snep_proxy,
+ GPOINTER_TO_UINT(target),
+ snep_type,
+ ndef_msg,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ snep_send_client_request,
+ parameter);
+
+ return NET_NFC_OK;
+}
+#if 0
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_snep_send_client_request_sync(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_type_t snep_type,
+ ndef_message_h msg,
+ net_nfc_snep_type_t *resp_type,
+ ndef_message_h *response)
+{
+ GVariant *resp_msg = NULL;
+ GVariant *arg_msg = NULL;
+ GError *error = NULL;
+ net_nfc_error_e result;
+ guint type;
+
+ if (target == NULL || msg == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ arg_msg = snep_message_to_variant(msg);
+
+ if (net_nfc_gdbus_snep_call_client_request_sync(snep_proxy,
+ GPOINTER_TO_UINT(target),
+ snep_type,
+ arg_msg,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ resp_type,
+ &resp_msg,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG(" send client request (sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+
+ *response = NULL;
+
+ if (result == NET_NFC_OK)
+ {
+ data_s ndef_data = { NULL, };
+
+ net_nfc_util_gdbus_variant_to_data_s(resp_msg, &ndef_data);
+
+ if (ndef_data.buffer != NULL && ndef_data.length > 0)
+ {
+ result = net_nfc_create_ndef_message_from_rawdata(
+ response,
+ &ndef_data);
+
+ net_nfc_util_free_data(&ndef_data);
+ }
+ }
+
+ return result;
+}
+#endif
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_snep_stop_service_sync(
+ net_nfc_target_handle_h target,
+ net_nfc_snep_handle_h service)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ if (target == NULL || service == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_snep_call_stop_snep_sync(
+ snep_proxy,
+ GPOINTER_TO_UINT(target),
+ GPOINTER_TO_UINT(service),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep stop service(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+static void _snep_event_cb(NetNfcGDbusSnep *object,
+ guint arg_handle,
+ guint arg_event,
+ gint arg_result,
+ GVariant *arg_ndef_msg,
+ guint arg_user_data)
+{
+ GVariant *parameter = (GVariant *)GUINT_TO_POINTER(arg_user_data);
+
+ INFO_MSG(">>> SIGNAL arrived");
+
+ DEBUG_CLIENT_MSG("handle [%p], event [%d], result [%d], user_data [%p]",
+ GUINT_TO_POINTER(arg_handle),
+ arg_event,
+ arg_result,
+ parameter);
+
+ if (parameter != NULL)
+ {
+ net_nfc_client_snep_event_cb callback;
+ void *user_data;
+
+ g_variant_get(parameter,
+ "(uu)",
+ &callback,
+ &user_data);
+
+ if (callback != NULL)
+ {
+ ndef_message_h message =
+ snep_variant_to_message(arg_ndef_msg);
+
+ callback(GUINT_TO_POINTER(arg_handle),
+ arg_event,
+ arg_result,
+ message,
+ user_data);
+ }
+
+ if (arg_event == NET_NFC_LLCP_UNREGISTERED) {
+ g_variant_unref(parameter);
+ }
+ }
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_snep_register_server(const char *san,
+ sap_t sap,
+ net_nfc_client_snep_event_cb callback,
+ void *user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+ GVariant *parameter;
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+
+ if (net_nfc_gdbus_snep_call_server_register_sync(snep_proxy,
+ sap,
+ san,
+ GPOINTER_TO_UINT(parameter),
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep register server(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+ g_variant_unref(parameter);
+
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return result;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_snep_unregister_server(const char *san,
+ sap_t sap)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get Snep Proxy");
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_snep_call_server_unregister_sync(snep_proxy,
+ sap,
+ san,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("snep unregister server(sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+
+ result = NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_client_snep_init(void)
+{
+ GError *error = NULL;
+
+ if (snep_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ snep_proxy = net_nfc_gdbus_snep_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Snep",
+ NULL,
+ &error);
+ if (snep_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ g_signal_connect(snep_proxy, "snep-event",
+ G_CALLBACK(_snep_event_cb), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_snep_deinit(void)
+{
+ if (snep_proxy)
+ {
+ g_object_unref(snep_proxy);
+ snep_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Ecore_X.h"
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_system_handler.h"
+
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+typedef struct _PopupFuncData PopupFuncData;
+
+struct _PopupFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusPopup *popup_proxy = NULL;
+static int popup_state = 0;
+
+static void popup_set_active_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void popup_set_active_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ PopupFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_popup_set_state_callback callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_popup_call_set_finish(
+ NET_NFC_GDBUS_POPUP(source_object),
+ res,
+ &error) == FALSE)
+ {
+
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish popup_set_active: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_popup_set_state_callback)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(result, data);
+
+ g_free(func_data);
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_sys_handler_set_state(int state,
+ net_nfc_client_popup_set_state_callback callback,
+ void *user_data)
+{
+ gboolean active = FALSE;
+ PopupFuncData *func_data;
+ net_nfc_launch_popup_check_e focus_state = CHECK_FOREGROUND;
+
+ if (popup_proxy == NULL )
+ return NET_NFC_NOT_INITIALIZED;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(PopupFuncData, 1);
+ if (func_data == NULL )
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ if (state == true)
+ active = TRUE;
+
+ net_nfc_gdbus_popup_call_set(popup_proxy,
+ active,
+ focus_state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ popup_set_active_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_sys_handler_set_state_sync(int state)
+{
+ GError *error = NULL;
+ net_nfc_launch_popup_check_e focus_state = CHECK_FOREGROUND;
+
+ if (popup_proxy == NULL)
+ return NET_NFC_NOT_INITIALIZED;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_popup_call_set_sync(popup_proxy,
+ (gboolean)state,
+ focus_state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call SetActive: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_sys_handler_set_state_force(int state,
+ net_nfc_client_popup_set_state_callback callback,
+ void *user_data)
+{
+ gboolean active = FALSE;
+ PopupFuncData *func_data;
+ net_nfc_launch_popup_check_e focus_state = NO_CHECK_FOREGROUND;
+
+ if (popup_proxy == NULL)
+ return NET_NFC_NOT_INITIALIZED;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(PopupFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ if (state == true)
+ active = TRUE;
+
+ net_nfc_gdbus_popup_call_set(popup_proxy,
+ active,
+ focus_state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ popup_set_active_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_sys_handler_set_state_force_sync(int state)
+{
+ GError *error = NULL;
+ net_nfc_launch_popup_check_e focus_state = NO_CHECK_FOREGROUND;
+
+ if (popup_proxy == NULL)
+ return NET_NFC_NOT_INITIALIZED;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_popup_call_set_sync(popup_proxy,
+ (gboolean)state,
+ focus_state,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call SetActive: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state(
+ int enable)
+{
+ net_nfc_error_e ret;
+
+ popup_state = enable;
+
+ if (enable)
+ {
+ ret = net_nfc_client_sys_handler_set_state_sync(
+ NET_NFC_LAUNCH_APP_SELECT);
+ }
+ else
+ {
+ ret = net_nfc_client_sys_handler_set_state_sync(
+ NET_NFC_NO_LAUNCH_APP_SELECT);
+ }
+
+ return ret;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force(
+ int enable)
+{
+ net_nfc_error_e ret;
+
+ popup_state = enable;
+
+ if (enable)
+ {
+ ret = net_nfc_client_sys_handler_set_state_force_sync(
+ NET_NFC_LAUNCH_APP_SELECT);
+ }
+ else
+ {
+ ret = net_nfc_client_sys_handler_set_state_force_sync(
+ NET_NFC_NO_LAUNCH_APP_SELECT);
+ }
+
+ return ret;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state(
+ int *state)
+{
+ if (state == NULL)
+ return NET_NFC_NULL_PARAMETER;
+#if 1
+ *state = popup_state;
+#else
+ /* TODO : get state from server */
+ GError *error = NULL;
+
+ if (popup_proxy == NULL) {
+ DEBUG_ERR_MSG("popup_proxy is null");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ if (net_nfc_gdbus_popup_call_get_sync(popup_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ state,
+ NULL,
+ &error) == false) {
+ DEBUG_CLIENT_MSG("net_nfc_gdbus_popup_call_get_sync failed: %s",
+ error->message);
+ g_error_free(error);
+
+ return NET_NFC_IPC_FAIL;
+ }
+#endif
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_client_sys_handler_init(void)
+{
+ GError *error = NULL;
+
+ if (popup_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ popup_proxy = net_nfc_gdbus_popup_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Popup",
+ NULL,
+ &error);
+ if (popup_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_OPERATION_FAIL;
+ }
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_sys_handler_deinit(void)
+{
+ if (popup_proxy)
+ {
+ g_object_unref(popup_proxy);
+ popup_proxy = NULL;
+ }
+}
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
-
+ *
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#include <string.h>
-#include <pthread.h>
-
-#include "net_nfc_tag.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_client_ipc_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_client_nfc_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_data.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_tag.h"
+#include "net_nfc_client_tag_internal.h"
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
#endif
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_format_ndef(net_nfc_target_handle_h handle, data_h key, void *trans_param)
+typedef struct _TagFuncData TagFuncData;
+
+struct _TagFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static NetNfcGDbusTag *tag_proxy = NULL;
+
+static TagFuncData *tag_discovered_func_data = NULL;
+static TagFuncData *tag_detached_func_data = NULL;
+
+static net_nfc_target_info_s *client_target_info = NULL;
+static net_nfc_event_filter_e client_filter = NET_NFC_ALL_ENABLE;
+
+static gboolean tag_check_filter(net_nfc_target_type_e type);
+
+static void tag_get_info_list(guint8 *buffer,
+ gint number_of_keys,
+ net_nfc_tag_info_s **list);
+
+static void tag_get_target_info(guint handle,
+ guint dev_type,
+ gboolean is_ndef_supported,
+ guchar ndef_card_state,
+ guint max_data_size,
+ guint actual_data_size,
+ guint number_of_keys,
+ GVariant *target_info_values,
+ GVariant *raw_data,
+ net_nfc_target_info_s **info);
+
+
+/* async callback */
+static void tag_is_tag_connected(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void tag_get_current_tag_info(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void tag_get_current_target_handle(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+/* signal callback */
+static void tag_tag_discovered(NetNfcGDbusTag *object,
+ guint arg_handle,
+ gint arg_dev_type,
+ gboolean arg_is_ndef_supported,
+ guchar arg_ndef_card_state,
+ guint arg_max_data_size,
+ guint arg_actual_data_size,
+ guint arg_number_of_keys,
+ GVariant *arg_target_info_values,
+ GVariant *arg_raw_data,
+ gpointer user_data);
+
+static void tag_tag_detached(NetNfcGDbusTag *object,
+ guint arg_handle,
+ gint arg_dev_type,
+ gpointer user_data);
+
+static gboolean tag_check_filter(net_nfc_target_type_e type)
{
- net_nfc_error_e ret;
- net_nfc_request_format_ndef_t *request = NULL;
- uint32_t length = 0;
- data_s *struct_key = (data_s *)key;
+ net_nfc_event_filter_e converted = NET_NFC_ALL_ENABLE;
+
+ DEBUG_CLIENT_MSG("client filter = %d", client_filter);
- if (handle == NULL)
+ if (type >= NET_NFC_ISO14443_A_PICC &&
+ type <= NET_NFC_MIFARE_DESFIRE_PICC)
{
- return NET_NFC_NULL_PARAMETER;
+ converted = NET_NFC_ISO14443A_ENABLE;
}
-
- length = sizeof(net_nfc_request_format_ndef_t);
- if (struct_key != NULL)
+ else if (type >= NET_NFC_ISO14443_B_PICC &&
+ type <= NET_NFC_ISO14443_BPRIME_PICC)
{
- length += struct_key->length;
+ converted = NET_NFC_ISO14443B_ENABLE;
}
-
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
+ else if (type == NET_NFC_FELICA_PICC)
+ {
+ converted = NET_NFC_FELICA_ENABLE;
+ }
+ else if (type == NET_NFC_JEWEL_PICC)
{
- return NET_NFC_ALLOC_FAIL;
+ converted = NET_NFC_FELICA_ENABLE;
+ }
+ else if (type == NET_NFC_ISO15693_PICC)
+ {
+ converted = NET_NFC_ISO15693_ENABLE;
}
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_FORMAT_NDEF;
- request->handle = (net_nfc_target_handle_s *)handle;
- request->trans_param = trans_param;
+ if ((converted & client_filter) == 0)
+ return FALSE;
- if (struct_key != NULL && struct_key->length > 0)
+ return TRUE;
+}
+
+static void tag_get_info_list(guint8 *buffer,
+ gint number_of_keys,
+ net_nfc_tag_info_s **list)
+{
+ net_nfc_tag_info_s *tmp_list = NULL;
+ net_nfc_tag_info_s *current = NULL;
+
+ gint i = 0;
+ gint length;
+
+ guint8 *pos = buffer;
+
+ if (buffer == NULL)
+ return;
+
+ tmp_list = g_new0(net_nfc_tag_info_s, number_of_keys);
+ current = tmp_list;
+
+ while(i < number_of_keys)
{
- request->key.length = struct_key->length;
- memcpy(&request->key.buffer, struct_key->buffer, request->key.length);
- }
+ gchar *str = NULL;
+ data_h value = NULL;
+
+ /* key */
+ length = *pos; /* first values is length of key */
+ pos++;
+
+ str = g_new0(gchar, length + 1);
+ memcpy(str, pos, length);
+
+ DEBUG_CLIENT_MSG("key = [%s]", str);
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
+ pos += length;
- _net_nfc_util_free_mem(request);
+ current->key = str;
- return ret;
+ /* value */
+ length = *pos; /* first value is length of value */
+ pos++;
+
+ value = NULL;
+ if (length > 0)
+ {
+ net_nfc_create_data(&value, pos, length);
+ pos += length;
+ }
+
+ current->value = value;
+
+ current++;
+ i++;
+ }
+
+ *list = tmp_list;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_tag_filter(net_nfc_event_filter_e config)
+static void tag_get_target_info(guint handle,
+ guint dev_type,
+ gboolean is_ndef_supported,
+ guchar ndef_card_state,
+ guint max_data_size,
+ guint actual_data_size,
+ guint number_of_keys,
+ GVariant *target_info_values,
+ GVariant *raw_data,
+ net_nfc_target_info_s **info)
{
- client_context_t *client_context = net_nfc_get_client_context();
+ guint8 *buffer = NULL;
+ net_nfc_target_info_s *info_data = NULL;
+ net_nfc_tag_info_s *list = NULL;
- pthread_mutex_lock(&(client_context->g_client_lock));
- client_context->filter = config;
- pthread_mutex_unlock(&(client_context->g_client_lock));
+ if (info == NULL)
+ return;
- return NET_NFC_OK;
+ net_nfc_util_gdbus_variant_to_buffer(target_info_values,
+ &buffer, NULL);
+
+ tag_get_info_list(buffer, number_of_keys, &list);
+
+ info_data = g_new0(net_nfc_target_info_s, 1);
+
+ info_data->ndefCardState = ndef_card_state;
+ info_data->actualDataSize = actual_data_size;
+ info_data->maxDataSize = max_data_size;
+ info_data->devType = dev_type;
+ info_data->handle = GUINT_TO_POINTER(handle);
+ info_data->is_ndef_supported = (uint8_t)is_ndef_supported;
+ info_data->number_of_keys = number_of_keys;
+ info_data->tag_info_list = list;
+
+ net_nfc_util_gdbus_variant_to_data_s(raw_data,
+ &info_data->raw_data);
+
+ *info = info_data;
}
-NET_NFC_EXPORT_API net_nfc_event_filter_e net_nfc_get_tag_filter()
+static void tag_is_tag_connected(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ TagFuncData *func_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ gboolean out_is_connected = FALSE;
+ net_nfc_target_type_e out_dev_type;
+
+ net_nfc_client_tag_is_tag_connected_completed callback;
- client_context_t *client_context = net_nfc_get_client_context();
+ if (net_nfc_gdbus_tag_call_is_tag_connected_finish(
+ NET_NFC_GDBUS_TAG(source_object),
+ &out_is_connected,
+ (gint32 *)&out_dev_type,
+ res,
+ &error) == FALSE)
+ {
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish is_tag_connected: %s",
+ error->message);
+ g_error_free(error);
+
+ }
- pthread_mutex_lock(&(client_context->g_client_lock));
- net_nfc_event_filter_e filter = client_context->filter;
- pthread_mutex_unlock(&(client_context->g_client_lock));
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
- return filter;
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ if (out_is_connected == FALSE)
+ result = NET_NFC_NOT_CONNECTED;
+
+ callback = (net_nfc_client_tag_is_tag_connected_completed)
+ func_data->callback;
+ callback(result, out_dev_type, func_data->user_data);
+
+ g_free(func_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_transceive(net_nfc_target_handle_h handle, data_h rawdata, void *trans_param)
+static void tag_get_current_tag_info(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- net_nfc_error_e ret;
- net_nfc_request_transceive_t *request = NULL;
- client_context_t *client_context_tmp = NULL;
- net_nfc_target_info_s *target_info = NULL;
- uint32_t length = 0;
- data_s *data = (data_s *)rawdata;
- uint8_t *send_buffer;
+ TagFuncData *func_data;
- DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+ net_nfc_error_e result = NET_NFC_OK;
- if (handle == NULL || rawdata == NULL)
+ net_nfc_target_type_e out_dev_type;
+ gboolean out_is_connected = FALSE;
+ gboolean out_is_ndef_supported = FALSE;
+ guchar out_ndef_card_state;
+ guint out_handle;
+ guint out_max_data_size;
+ guint out_actual_data_size;
+ guint out_number_of_keys;
+ GVariant *out_target_info_values = NULL;
+ GVariant *out_raw_data = NULL;
+
+ GError *error = NULL;
+
+ net_nfc_client_tag_get_current_tag_info_completed callback;
+
+ /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
+ net_nfc_target_info_s *info_s = NULL;
+
+ if (net_nfc_gdbus_tag_call_get_current_tag_info_finish (
+ NET_NFC_GDBUS_TAG(source_object),
+ &out_is_connected,
+ &out_handle,
+ (gint *)&out_dev_type,
+ &out_is_ndef_supported,
+ &out_ndef_card_state,
+ &out_max_data_size,
+ &out_actual_data_size,
+ &out_number_of_keys,
+ &out_target_info_values,
+ &out_raw_data,
+ res,
+ &error) == FALSE)
{
- return NET_NFC_NULL_PARAMETER;
+ result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish get_current_tag_info: %s",
+ error->message);
+ g_error_free(error);
}
- if (!net_nfc_tag_is_connected())
+ func_data = user_data;
+ if(func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
{
- return NET_NFC_OPERATION_FAIL;
+ g_free(func_data);
+ return;
}
- client_context_tmp = net_nfc_get_client_context();
- if (client_context_tmp == NULL || client_context_tmp->target_info == NULL)
+ if (out_is_connected == FALSE)
+ result = NET_NFC_NOT_CONNECTED;
+
+ callback = (net_nfc_client_tag_get_current_tag_info_completed)
+ func_data->callback;
+
+ if (result != NET_NFC_OK)
{
- return NET_NFC_NO_DATA_FOUND;
+ callback(result, NULL, func_data->user_data);
+ g_free(func_data);
+ return;
}
- /* fill trans information struct */
- target_info = client_context_tmp->target_info;
- switch (target_info->devType)
+ if (tag_check_filter(out_dev_type) == FALSE)
+ DEBUG_CLIENT_MSG("The detected target is filtered out");
+
+ net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
+
+ tag_get_target_info(out_handle,
+ out_dev_type,
+ out_is_ndef_supported,
+ out_ndef_card_state,
+ out_max_data_size,
+ out_actual_data_size,
+ out_number_of_keys,
+ out_target_info_values,
+ out_raw_data,
+ &info_s);
+
+ client_target_info = info_s;
+
+ callback(result, info_s, func_data->user_data);
+
+ g_free(func_data);
+}
+
+static void tag_get_current_target_handle(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TagFuncData *func_data;
+
+ net_nfc_target_handle_h handle = NULL;
+ net_nfc_target_type_e out_dev_type;
+
+ gboolean out_is_connected = FALSE;
+ guint out_handle = 0;
+
+ net_nfc_error_e result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_tag_get_current_target_handle_completed callback;
+
+ if (net_nfc_gdbus_tag_call_get_current_target_handle_finish(
+ NET_NFC_GDBUS_TAG(source_object),
+ &out_is_connected,
+ &out_handle,
+ (gint *)&out_dev_type,
+ res,
+ &error) == FALSE)
{
- case NET_NFC_MIFARE_MINI_PICC :
- case NET_NFC_MIFARE_1K_PICC :
- case NET_NFC_MIFARE_4K_PICC :
- case NET_NFC_MIFARE_ULTRA_PICC :
- {
- length = sizeof(net_nfc_request_transceive_t) + data->length + 2;
+ result = NET_NFC_UNKNOWN_ERROR;
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
+ DEBUG_ERR_MSG("Can not finish get_current_target_handle: %s",
+ error->message);
+ g_error_free(error);
+ }
- _net_nfc_util_alloc_mem(send_buffer, data->length + 2);
- if (send_buffer == NULL)
- {
- _net_nfc_util_free_mem(request);
- return NET_NFC_ALLOC_FAIL;
- }
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
- memcpy(send_buffer, data->buffer, data->length);
- net_nfc_util_compute_CRC(CRC_A, send_buffer, data->length + 2);
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
- memcpy(&request->info.trans_data.buffer, send_buffer, data->length + 2);
+ callback = (net_nfc_client_tag_get_current_target_handle_completed)
+ func_data->callback;
- request->info.trans_data.length = data->length + 2;
+ if (out_is_connected == FALSE)
+ result = NET_NFC_NOT_CONNECTED;
- _net_nfc_util_free_mem(send_buffer);
- }
- break;
+ if (out_handle)
+ handle = GUINT_TO_POINTER(out_handle);
- case NET_NFC_JEWEL_PICC :
- {
- if (data->length > 9)
- {
- return NET_NFC_INVALID_PARAM;
- }
+ callback(result, handle, func_data->user_data);
- length = sizeof(net_nfc_request_transceive_t) + 9;
+ g_free(func_data);
+}
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
+static void tag_tag_discovered(NetNfcGDbusTag *object,
+ guint arg_handle,
+ gint arg_dev_type,
+ gboolean arg_is_ndef_supported,
+ guchar arg_ndef_card_state,
+ guint arg_max_data_size,
+ guint arg_actual_data_size,
+ guint arg_number_of_keys,
+ GVariant *arg_target_info_values,
+ GVariant *arg_raw_data,
+ gpointer user_data)
+{
+ /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
+ net_nfc_target_info_s *info_s = NULL;
- _net_nfc_util_alloc_mem(send_buffer, 9);
- if (send_buffer == NULL)
- {
- _net_nfc_util_free_mem(request);
- return NET_NFC_ALLOC_FAIL;
- }
+ net_nfc_client_tag_tag_discovered callback;
- memcpy(send_buffer, data->buffer, data->length);
- net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
+ INFO_MSG(">>> SIGNAL arrived");
- memcpy(&request->info.trans_data.buffer, send_buffer, 9);
+ if (tag_discovered_func_data == NULL)
+ return;
- request->info.trans_data.length = 9;
+ if (tag_discovered_func_data->callback == NULL)
+ return;
- _net_nfc_util_free_mem(send_buffer);
- }
- break;
+ if (tag_check_filter(arg_dev_type) == FALSE)
+ DEBUG_CLIENT_MSG("The detected target is filtered out");
- default :
- {
- length = sizeof(net_nfc_request_transceive_t) + data->length;
+ net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
+ tag_get_target_info(arg_handle,
+ arg_dev_type,
+ arg_is_ndef_supported,
+ arg_ndef_card_state,
+ arg_max_data_size,
+ arg_actual_data_size,
+ arg_number_of_keys,
+ arg_target_info_values,
+ arg_raw_data,
+ &info_s);
- memcpy(&request->info.trans_data.buffer, data->buffer, data->length);
+ client_target_info = info_s;
- request->info.trans_data.length = data->length;
- }
- break;
- }
+ callback = (net_nfc_client_tag_tag_discovered)
+ tag_discovered_func_data->callback;
+
+ callback(info_s, tag_discovered_func_data->user_data);
+}
+
+static void tag_tag_detached(NetNfcGDbusTag *object,
+ guint arg_handle,
+ gint arg_dev_type,
+ gpointer user_data)
+{
+ net_nfc_client_tag_tag_detached callback;
- /* fill request message */
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_TRANSCEIVE;
- request->handle = (net_nfc_target_handle_s *)handle;
- request->trans_param = trans_param;
- request->info.dev_type = (uint32_t)target_info->devType;
+ INFO_MSG(">>> SIGNAL arrived");
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
+ if (tag_detached_func_data == NULL)
+ return;
- _net_nfc_util_free_mem(request);
+ if (tag_detached_func_data->callback == NULL)
+ return;
- return ret;
+ if (tag_check_filter(arg_dev_type) == FALSE)
+ DEBUG_CLIENT_MSG("The detected target is filtered out");
+
+ /*FIXME: currently SAVE_TARGET_INFO_IN_CC support only */
+ net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
+
+ callback = (net_nfc_client_tag_tag_detached)
+ tag_detached_func_data->callback;
+
+ callback(tag_detached_func_data->user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_read_tag(net_nfc_target_handle_h handle, void *trans_param)
+/* internal funcion */
+gboolean net_nfc_client_tag_is_connected(void)
{
- net_nfc_error_e ret;
- net_nfc_request_read_ndef_t request = { 0, };
+ if (client_target_info == NULL)
+ return FALSE;
- DEBUG_CLIENT_MSG("send reqeust :: read ndef = [%p]", handle);
+ if (client_target_info->handle == NULL)
+ return FALSE;
- if (handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
+ return TRUE;
+}
- if (!net_nfc_tag_is_connected())
- {
- return NET_NFC_OPERATION_FAIL;
+net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void)
+{
+ return client_target_info;
+}
+
+/* public APIs */
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_tag_is_tag_connected(
+ net_nfc_client_tag_is_tag_connected_completed callback,
+ void *user_data)
+{
+ TagFuncData *func_data;
+
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
}
- request.length = sizeof(net_nfc_request_read_ndef_t);
- request.request_type = NET_NFC_MESSAGE_READ_NDEF;
- request.handle = (net_nfc_target_handle_s *)handle;
- request.trans_param = trans_param;
+ func_data = g_new0(TagFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ net_nfc_gdbus_tag_call_is_tag_connected(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ tag_is_tag_connected,
+ func_data);
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_write_ndef(net_nfc_target_handle_h handle, ndef_message_h msg, void *trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_tag_is_tag_connected_sync(
+ net_nfc_target_type_e *dev_type)
{
- net_nfc_request_write_ndef_t *request = NULL;
- net_nfc_error_e result;
- data_s data;
- uint32_t length = 0, ndef_length = 0;
+ net_nfc_target_type_e out_dev_type;
- DEBUG_CLIENT_MSG("send reqeust :: write ndef = [%p]", handle);
+ gboolean out_is_connected = FALSE;
- if (handle == NULL || msg == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
+ GError *error = NULL;
- if (!net_nfc_tag_is_connected())
- {
- return NET_NFC_OPERATION_FAIL;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
}
- ndef_length = net_nfc_util_get_ndef_message_length((ndef_message_s *)msg);
- if (ndef_length == 0)
+ if (net_nfc_gdbus_tag_call_is_tag_connected_sync(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_is_connected,
+ (gint *)&out_dev_type,
+ NULL,
+ &error) == FALSE)
{
- return NET_NFC_INVALID_PARAM;
+ DEBUG_ERR_MSG("Can not get is_tag_connected result: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
- length = sizeof(net_nfc_request_write_ndef_t) + ndef_length;
+ if (dev_type)
+ *dev_type = out_dev_type;
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
- return NET_NFC_ALLOC_FAIL;
- }
+ if (out_is_connected == FALSE)
+ return NET_NFC_NOT_CONNECTED;
- /* fill request message */
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_WRITE_NDEF;
- request->handle = (net_nfc_target_handle_s *)handle;
- request->trans_param = trans_param;
- request->data.length = ndef_length;
+ return NET_NFC_OK;
+}
- data.length = ndef_length;
- data.buffer = request->data.buffer;
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_tag_get_current_tag_info(
+ net_nfc_client_tag_get_current_tag_info_completed callback,
+ void *user_data)
+{
+ TagFuncData *func_data;
- result = net_nfc_util_convert_ndef_message_to_rawdata((ndef_message_s *)msg, &data);
- if (result != NET_NFC_OK)
- {
- DEBUG_CLIENT_MSG("NDEF to rawdata is failed (reason:%d)", result);
- _net_nfc_util_free_mem(request);
- return result;
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
}
- result = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
+ func_data = g_new0(TagFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- _net_nfc_util_free_mem(request);
- return result;
+ net_nfc_gdbus_tag_call_get_current_tag_info(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ tag_get_current_tag_info,
+ func_data);
+
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_tag_connected(void *trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_tag_get_current_tag_info_sync(
+ net_nfc_target_info_h *info)
{
- net_nfc_request_is_tag_connected_t request = { 0, };
- net_nfc_error_e result;
+ net_nfc_target_type_e out_dev_type;
+ gboolean out_is_connected = FALSE;
+ gboolean out_is_ndef_supported;
+ guchar out_ndef_card_state;
+ guint out_handle;
+ guint out_max_data_size;
+ guint out_actual_data_size;
+ guint out_number_of_keys;
+ GVariant *out_target_info_values;
+ GVariant *out_raw_data;
+
+ net_nfc_target_info_s *info_s = NULL;
+
+ GError *error = NULL;
+
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- request.length = sizeof(net_nfc_request_is_tag_connected_t);
- request.request_type = NET_NFC_MESSAGE_IS_TAG_CONNECTED;
- request.trans_param = trans_param;
+ if (net_nfc_gdbus_tag_call_get_current_tag_info_sync(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_is_connected,
+ &out_handle,
+ (gint *)&out_dev_type,
+ &out_is_ndef_supported,
+ &out_ndef_card_state,
+ &out_max_data_size,
+ &out_actual_data_size,
+ &out_number_of_keys,
+ &out_target_info_values,
+ &out_raw_data,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can no get current_tag_info result: %s",
+ error->message);
- result = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- return result;
-}
+ if (out_is_connected == FALSE)
+ return NET_NFC_NOT_CONNECTED;
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_is_tag_connected_sync(int *dev_type)
-{
- net_nfc_request_is_tag_connected_t request = { 0, };
- net_nfc_response_is_tag_connected_t context = { 0, };
- net_nfc_error_e result;
+ /* TODO : do something */
+ if (info == NULL)
+ return NET_NFC_OK;
- if (dev_type == NULL)
- return NET_NFC_INVALID_PARAM;
+ if(tag_check_filter(out_dev_type) == FALSE)
+ DEBUG_CLIENT_MSG("The detected target is filtered out");
- request.length = sizeof(net_nfc_request_is_tag_connected_t);
- request.request_type = NET_NFC_MESSAGE_IS_TAG_CONNECTED;
- request.trans_param = (void *)&context;
+ tag_get_target_info(out_handle,
+ out_dev_type,
+ out_is_ndef_supported,
+ out_ndef_card_state,
+ out_max_data_size,
+ out_actual_data_size,
+ out_number_of_keys,
+ out_target_info_values,
+ out_raw_data,
+ &info_s);
- result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL);
- if (result == NET_NFC_OK)
- {
- *dev_type = context.devType;
- }
+ *info = info_s;
- return result;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_make_read_only_ndef_tag(net_nfc_target_handle_h handle, void *trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_tag_get_current_target_handle(
+ net_nfc_client_tag_get_current_target_handle_completed callback,
+ void *user_data)
{
- net_nfc_error_e result;
- net_nfc_request_make_read_only_ndef_t request = { 0, };
- client_context_t *tmp_client_context = NULL;
- net_nfc_target_info_s *target_info = NULL;
+ TagFuncData *func_data;
- DEBUG_CLIENT_MSG("send reqeust :: make read only ndef tag = [%p]", handle);
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
- if (handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
}
- if (!net_nfc_tag_is_connected())
- {
- return NET_NFC_OPERATION_FAIL;
+ func_data = g_new0(TagFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_tag_call_get_current_target_handle(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ tag_get_current_target_handle,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_tag_get_current_target_handle_sync(
+ net_nfc_target_handle_h *handle)
+{
+ net_nfc_target_type_e out_dev_type;
+ gboolean out_is_connected = FALSE;
+ guint out_handle;
+ GError *error = NULL;
+
+ if (tag_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
}
- tmp_client_context = net_nfc_get_client_context();
- if (tmp_client_context != NULL)
+ if (net_nfc_gdbus_tag_call_get_current_target_handle_sync(tag_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ &out_is_connected,
+ &out_handle,
+ (gint *)&out_dev_type,
+ NULL,
+ &error) == FALSE)
{
- target_info = tmp_client_context->target_info;
+ DEBUG_ERR_MSG("Can no get current_target_handle result: %s",
+ error->message);
- if (target_info != NULL)
- {
- bool is_supported_tag = false;
-
- switch (target_info->devType)
- {
- case NET_NFC_ISO14443_A_PICC :
- case NET_NFC_MIFARE_MINI_PICC :
- case NET_NFC_MIFARE_1K_PICC :
- case NET_NFC_MIFARE_4K_PICC :
- case NET_NFC_MIFARE_ULTRA_PICC :
- case NET_NFC_JEWEL_PICC :
- is_supported_tag = true;
- break;
- default :
- is_supported_tag = false;
- break;
- }
-
- if (!is_supported_tag)
- {
- DEBUG_MSG("not supported tag for read only ndef tag");
- return NET_NFC_NOT_SUPPORTED;
- }
- }
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
- request.length = sizeof(net_nfc_request_make_read_only_ndef_t);
- request.request_type = NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF;
- request.handle = (net_nfc_target_handle_s *)handle;
- request.trans_param = trans_param;
+ if (out_is_connected == FALSE)
+ return NET_NFC_NOT_CONNECTED;
- result = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ if (handle)
+ *handle = GUINT_TO_POINTER(out_handle);
- return result;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_tag_info(void *trans_param)
+NET_NFC_EXPORT_API
+void net_nfc_client_tag_set_tag_discovered(
+ net_nfc_client_tag_tag_discovered callback,
+ void *user_data)
{
- net_nfc_request_get_current_tag_info_t request = { 0, };
- net_nfc_error_e result = NET_NFC_OK;
+ if (tag_discovered_func_data == NULL)
+ tag_discovered_func_data = g_new0(TagFuncData, 1);
- request.length = sizeof(net_nfc_request_get_current_tag_info_t);
- request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO;
- request.trans_param = trans_param;
+ tag_discovered_func_data->callback = (gpointer) callback;
+ tag_discovered_func_data->user_data = user_data;
+}
- result = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+NET_NFC_EXPORT_API
+void net_nfc_client_tag_unset_tag_discovered(void)
+{
+ if (tag_discovered_func_data)
+ {
+ g_free(tag_discovered_func_data);
+ tag_discovered_func_data = NULL;
+ }
- return result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_current_tag_info_sync(net_nfc_target_info_h *info)
+NET_NFC_EXPORT_API
+void net_nfc_client_tag_set_tag_detached(
+ net_nfc_client_tag_tag_detached callback,
+ void *user_data)
{
- net_nfc_request_get_current_tag_info_t request = { 0, };
- net_nfc_response_get_current_tag_info_t response = { 0, };
- net_nfc_error_e result = NET_NFC_OK;
+ if (tag_detached_func_data == NULL)
+ tag_detached_func_data = g_new0(TagFuncData, 1);
- request.length = sizeof(net_nfc_request_get_current_tag_info_t);
- request.request_type = NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO;
- request.trans_param = (void *)&response;
+ tag_detached_func_data->callback = (gpointer) callback;
+ tag_detached_func_data->user_data = user_data;
+}
- result = net_nfc_client_send_request_sync((net_nfc_request_msg_t *)&request, NULL);
- if (result == NET_NFC_OK)
+NET_NFC_EXPORT_API
+void net_nfc_client_tag_unset_tag_detached(void)
+{
+ if (tag_detached_func_data)
{
- /* already allocated memory */
- *info = (net_nfc_target_info_h)response.trans_param;
+ g_free(tag_detached_func_data);
+ tag_detached_func_data = NULL;
}
+}
- return result;
+NET_NFC_EXPORT_API
+void net_nfc_client_tag_set_filter(net_nfc_event_filter_e filter)
+{
+ client_filter = filter;
}
-bool net_nfc_util_check_tag_filter(net_nfc_target_type_e type)
+NET_NFC_EXPORT_API
+net_nfc_event_filter_e net_nfc_client_tag_get_filter(void)
{
- net_nfc_event_filter_e current_filter = net_nfc_get_tag_filter();
- net_nfc_event_filter_e converted = NET_NFC_ALL_ENABLE;
+ return client_filter;
+}
- DEBUG_CLIENT_MSG("filter = [%d]", current_filter);
+net_nfc_error_e net_nfc_client_tag_init(void)
+{
+ GError *error = NULL;
- if (type >= NET_NFC_ISO14443_A_PICC && type <= NET_NFC_MIFARE_DESFIRE_PICC)
+ if (tag_proxy)
{
- converted = NET_NFC_ISO14443A_ENABLE;
+ DEBUG_CLIENT_MSG("Alrady initialized");
+ return NET_NFC_OK;
}
- else if (type >= NET_NFC_ISO14443_B_PICC && type <= NET_NFC_ISO14443_BPRIME_PICC)
+
+ if (client_target_info)
{
- converted = NET_NFC_ISO14443B_ENABLE;
+ net_nfc_release_tag_info(
+ (net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
}
- else if (type == NET_NFC_FELICA_PICC)
+
+ client_filter = NET_NFC_ALL_ENABLE;
+
+ tag_proxy = net_nfc_gdbus_tag_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Tag",
+ NULL,
+ &error);
+ if (tag_proxy == NULL)
{
- converted = NET_NFC_FELICA_ENABLE;
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
}
- else if (type == NET_NFC_JEWEL_PICC)
+
+ g_signal_connect(tag_proxy, "tag-discovered",
+ G_CALLBACK(tag_tag_discovered), NULL);
+
+ g_signal_connect(tag_proxy, "tag-detached",
+ G_CALLBACK(tag_tag_detached), NULL);
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_tag_deinit(void)
+{
+ if (tag_proxy)
{
- converted = NET_NFC_FELICA_ENABLE;
+ g_object_unref(tag_proxy);
+ tag_proxy = NULL;
}
- else if (type == NET_NFC_ISO15693_PICC)
+
+ if (tag_discovered_func_data)
{
- converted = NET_NFC_ISO15693_ENABLE;
+ g_free(tag_discovered_func_data);
+ tag_discovered_func_data = NULL;
}
- if ((converted & current_filter) == 0)
+ if (tag_detached_func_data)
{
- return false;
+ g_free(tag_detached_func_data);
+ tag_detached_func_data = NULL;
}
- return true;
+ net_nfc_release_tag_info((net_nfc_target_info_h)client_target_info);
+ client_target_info = NULL;
+
+ client_filter = NET_NFC_ALL_ENABLE;
}
* limitations under the License.
*/
-#include "net_nfc_tag.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_client_ipc_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_client_nfc_private.h"
-#include "net_nfc_tag_felica.h"
-#include "net_nfc_target_info.h"
-
+#include <glib.h>
#include <string.h>
+#include "net_nfc_client_tag_felica.h"
+#include "net_nfc_client_tag_internal.h"
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_target_info.h"
+
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
#endif
#define FELICA_CMD_REQ_SYSTEM_CODE 0x0C
#define FELICA_TAG_KEY "IDm"
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_poll(net_nfc_target_handle_h handle, net_nfc_felica_poll_request_code_e req_code, uint8_t time_slote, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_felica_poll(net_nfc_target_handle_h handle,
+ net_nfc_felica_poll_request_code_e req_code,
+ uint8_t time_slote,
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[6] = { 0x00, };
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
- if ((target_info = client_context_tmp->target_info) == NULL)
- {
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
if (target_info->devType != NET_NFC_FELICA_PICC)
{
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- uint8_t send_buffer[6] = { 0x00, };
-
/* total size of requet command */
send_buffer[0] = 0x06;
send_buffer[1] = FELICA_CMD_POLL;
DEBUG_MSG_PRINT_BUFFER(send_buffer, 6);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 6;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_request_service(net_nfc_target_handle_h handle, uint8_t number_of_area_service, uint16_t area_service_list[], uint8_t number_of_services, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_felica_request_service(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_area_service,
+ uint16_t area_service_list[],
+ uint8_t number_of_services,
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint32_t send_buffer_length;
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int i;
+
if (handle == NULL || area_service_list == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
- if ((target_info = client_context_tmp->target_info) == NULL)
- {
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
if (target_info->devType != NET_NFC_FELICA_PICC)
{
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- data_h IDm = NULL;
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK)
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
{
return NET_NFC_NO_DATA_FOUND;
}
if (((data_s*)IDm)->length != 8)
- {
-
return NET_NFC_OUT_OF_BOUND;
- }
if (number_of_area_service > 32)
- {
return NET_NFC_OUT_OF_BOUND;
- }
- uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services); /* size + cmd + UID + number of service service count + service list */
- uint8_t* send_buffer = NULL;
- uint8_t* temp = NULL;
+ /* size + cmd + UID + number of service service count + service list */
+ send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services);
_net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
- {
return NET_NFC_ALLOC_FAIL;
- }
temp = send_buffer;
*send_buffer = number_of_area_service;
send_buffer++;
- int i = 0;
-
- for (; i < number_of_services; i++)
+ for (i = 0; i < number_of_services; i++)
{
memcpy(send_buffer, &area_service_list[i], sizeof(uint16_t));
send_buffer = send_buffer + 2;
DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = send_buffer_length;
net_nfc_error_e result = NET_NFC_OK;
- result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ result = net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
if (temp != NULL)
_net_nfc_util_free_mem(temp);
return result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_request_response(net_nfc_target_handle_h handle, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_felica_request_response(
+ net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint8_t send_buffer[10] = { 0x00, };
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
- if ((target_info = client_context_tmp->target_info) == NULL)
- {
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
if (target_info->devType != NET_NFC_FELICA_PICC)
{
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- data_h IDm = NULL;
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK)
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
{
return NET_NFC_NO_DATA_FOUND;
}
if (((data_s*)IDm)->length != 8)
- {
-
return NET_NFC_OUT_OF_BOUND;
- }
-
- uint8_t send_buffer[10] = { 0x00, };
send_buffer[0] = 0xA;
send_buffer[1] = FELICA_CMD_REQ_RESPONSE;
- memcpy(send_buffer + 2, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length);
+ memcpy(send_buffer + 2,
+ ((data_s*)IDm)->buffer,
+ ((data_s*)IDm)->length);
DEBUG_MSG_PRINT_BUFFER(send_buffer, 10);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 10;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_read_without_encryption(net_nfc_target_handle_h handle, uint8_t number_of_services, uint16_t service_list[], uint8_t number_of_blocks, uint8_t block_list[], void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_felica_read_without_encryption(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_services,
+ uint16_t service_list[],
+ uint8_t number_of_blocks,
+ uint8_t block_list[],
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint32_t send_buffer_length;
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int i;
+
if (handle == NULL || service_list == NULL || block_list == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
- if ((target_info = client_context_tmp->target_info) == NULL)
- {
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
if (target_info->devType != NET_NFC_FELICA_PICC)
{
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- data_h IDm = NULL;
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK)
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
{
return NET_NFC_NO_DATA_FOUND;
}
if (((data_s*)IDm)->length != 8)
- {
-
return NET_NFC_OUT_OF_BOUND;
- }
if (number_of_services > 16)
- {
return NET_NFC_OUT_OF_BOUND;
- }
- uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services) + 1 + number_of_blocks;
- uint8_t* send_buffer = NULL;
- uint8_t* temp = NULL;
+ send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services)
+ + 1 + number_of_blocks;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
- {
return NET_NFC_ALLOC_FAIL;
- }
temp = send_buffer;
*send_buffer = number_of_services;
send_buffer++;
- int i = 0;
- for (; i < number_of_services; i++)
+ for (i = 0; i < number_of_services; i++)
{
memcpy(send_buffer, &service_list[i], sizeof(uint16_t));
send_buffer = send_buffer + 2;
DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
- data_s rawdata;
-
rawdata.buffer = temp;
rawdata.length = send_buffer_length;
net_nfc_error_e result = NET_NFC_OK;
- result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ result = net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
if (temp != NULL)
_net_nfc_util_free_mem(temp);
return result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_write_without_encryption(net_nfc_target_handle_h handle, uint8_t number_of_services, uint16_t service_list[], uint8_t number_of_blocks, uint8_t block_list[], data_h data, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_felica_write_without_encryption(
+ net_nfc_target_handle_h handle,
+ uint8_t number_of_services,
+ uint16_t service_list[],
+ uint8_t number_of_blocks,
+ uint8_t block_list[],
+ data_h data,
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
- if (handle == NULL || service_list == NULL || block_list == NULL || data == NULL)
- return NET_NFC_NULL_PARAMETER;
+ net_nfc_target_info_s* target_info = NULL;
- if (!net_nfc_tag_is_connected())
- {
- return NET_NFC_OPERATION_FAIL;
- }
+ data_s rawdata;
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
+ data_h IDm = NULL;
+
+ uint32_t send_buffer_length;
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
- if ((target_info = client_context_tmp->target_info) == NULL)
+ int i;
+
+ if (handle == NULL || service_list == NULL ||
+ block_list == NULL || data == NULL)
{
- return NET_NFC_NO_DATA_FOUND;
+ return NET_NFC_NULL_PARAMETER;
}
+ if(net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
+ return NET_NFC_NO_DATA_FOUND;
+
if (target_info->devType != NET_NFC_FELICA_PICC)
{
DEBUG_CLIENT_MSG("only Jewel tag is available");
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- data_h IDm = NULL;
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK)
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
{
return NET_NFC_NO_DATA_FOUND;
}
if (((data_s*)IDm)->length != 8)
- {
-
return NET_NFC_OUT_OF_BOUND;
- }
if (number_of_services > 16)
- {
return NET_NFC_OUT_OF_BOUND;
- }
if (((data_s*)data)->length > 16 * number_of_blocks)
- {
return NET_NFC_OUT_OF_BOUND;
- }
- uint32_t send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services) + 1 + number_of_blocks + ((data_s*)data)->length;
- uint8_t* send_buffer = NULL;
- uint8_t* temp = NULL;
+ send_buffer_length = 1 + 1 + 8 + 1 + (2 * number_of_services)
+ + 1 + number_of_blocks
+ +((data_s*)data)->length;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
- {
return NET_NFC_ALLOC_FAIL;
- }
temp = send_buffer;
*send_buffer = number_of_services;
send_buffer++;
- int i = 0;
- for (; i < number_of_services; i++)
+ for (i = 0; i < number_of_services; i++)
{
memcpy(send_buffer, &service_list[i], sizeof(uint16_t));
send_buffer = send_buffer + 2;
DEBUG_MSG_PRINT_BUFFER(temp, send_buffer_length);
- data_s rawdata;
-
rawdata.buffer = temp;
rawdata.length = send_buffer_length;
net_nfc_error_e result = NET_NFC_OK;
- result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ result = net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
if (temp != NULL)
_net_nfc_util_free_mem(temp);
return result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_felica_request_system_code(net_nfc_target_handle_h handle, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_felica_request_system_code(
+ net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h IDm = NULL;
+
+ uint8_t send_buffer[10] = { 0x00, };
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
-
- if ((target_info = client_context_tmp->target_info) == NULL)
- {
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
if (target_info->devType != NET_NFC_FELICA_PICC)
{
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- data_h IDm = NULL;
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, FELICA_TAG_KEY, &IDm) != NET_NFC_OK)
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ FELICA_TAG_KEY,
+ &IDm) != NET_NFC_OK)
{
return NET_NFC_NO_DATA_FOUND;
}
if (((data_s*)IDm)->length != 8)
- {
-
return NET_NFC_OUT_OF_BOUND;
- }
- uint8_t send_buffer[10] = { 0x00, };
send_buffer[0] = 0xA;
send_buffer[1] = FELICA_CMD_REQ_SYSTEM_CODE;
- memcpy(send_buffer + 2, ((data_s *)IDm)->buffer, ((data_s *)IDm)->length);
+ memcpy(send_buffer + 2,
+ ((data_s *)IDm)->buffer,
+ ((data_s *)IDm)->length);
DEBUG_MSG_PRINT_BUFFER(send_buffer, 10);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 10;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_tag.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_client_ipc_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_client_nfc_private.h"
-#include "net_nfc_tag_jewel.h"
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "net_nfc_client_tag_jewel.h"
+#include "net_nfc_client_tag_internal.h"
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_target_info.h"
-#include <string.h>
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
#endif
-
#define JEWEL_CMD_REQA 0x26
#define JEWEL_CMD_WUPA 0x52
#define JEWEL_CMD_RID 0x78
#define JEWEL_CMD_WRITE_NE 0x1A
#define JEWEL_TAG_KEY "UID"
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_read_id (net_nfc_target_handle_h handle, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[9] = {0x00, };
+
if(handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if(!net_nfc_tag_is_connected()){
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
-
- if((target_info = client_context_tmp->target_info) == NULL){
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
- if(target_info->devType != NET_NFC_JEWEL_PICC){
+ if(target_info->devType != NET_NFC_JEWEL_PICC)
+ {
DEBUG_CLIENT_MSG("only Jewel tag is available");
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- uint8_t send_buffer[9] = {0x00, };
send_buffer[0] = JEWEL_CMD_RID;
net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 9;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
-
-
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_read_byte (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t send_buffer[9] = {0x00, };
+
if(handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if(block > 0xE || byte > 0x7 ){
-
+ if(block > 0xE || byte > 0x7 )
return NET_NFC_OUT_OF_BOUND;
- }
- if(!net_nfc_tag_is_connected()){
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
- if((target_info = client_context_tmp->target_info) == NULL){
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
- if(target_info->devType != NET_NFC_JEWEL_PICC){
+ if(target_info->devType != NET_NFC_JEWEL_PICC)
+ {
DEBUG_CLIENT_MSG("only Jewel tag is available");
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- data_h UID = NULL;
-
- if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){
+ if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ JEWEL_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
return NET_NFC_NO_DATA_FOUND;
}
- if(((data_s*)UID)->length != 4){
-
+ if(((data_s*)UID)->length != 4)
return NET_NFC_OUT_OF_BOUND;
- }
-
- uint8_t send_buffer[9] = {0x00, };
/* command */
send_buffer[0] = JEWEL_CMD_READ;
send_buffer[2] = 0x00;
/* UID0 ~ 3 */
- memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length);
+ memcpy(&(send_buffer[3]),
+ ((data_s*)UID)->buffer,
+ ((data_s*)UID)->length);
net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 9;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_read_all (net_nfc_target_handle_h handle, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_h handle,
+ nfc_transceive_data_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t send_buffer[9] = {0x00, };
+
if(handle == NULL )
return NET_NFC_NULL_PARAMETER;
- if(!net_nfc_tag_is_connected()){
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
- if((target_info = client_context_tmp->target_info) == NULL){
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
- if(target_info->devType != NET_NFC_JEWEL_PICC){
+ if(target_info->devType != NET_NFC_JEWEL_PICC)
+ {
DEBUG_CLIENT_MSG("only Jewel tag is available");
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- data_h UID = NULL;
-
- if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){
+ if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ JEWEL_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
return NET_NFC_NO_DATA_FOUND;
}
- if(((data_s*)UID)->length != 4){
-
+ if(((data_s*)UID)->length != 4)
return NET_NFC_OUT_OF_BOUND;
- }
-
- uint8_t send_buffer[9] = {0x00, };
/* command */
send_buffer[0] = JEWEL_CMD_RALL;
send_buffer[2] = 0x00;
/* UID0 ~ 3 */
- memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length);
+ memcpy(&(send_buffer[3]),
+ ((data_s*)UID)->buffer,
+ ((data_s*)UID)->length);
net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
-
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 9;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
-
-
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_write_with_erase (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, uint8_t data, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_jewel_write_with_erase(
+ net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ uint8_t data,
+ nfc_transceive_callback callback,
+ void *user_data)
{
- if(handle == NULL)
- return NET_NFC_NULL_PARAMETER;
+ net_nfc_target_info_s* target_info = NULL;
+ data_s rawdata;
- if(block > 0xE || byte > 0x7 ){
+ data_h UID = NULL;
+
+ uint8_t send_buffer[9] = {0x00, };
+ if(handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if(block > 0xE || byte > 0x7 )
return NET_NFC_OUT_OF_BOUND;
- }
- if(!net_nfc_tag_is_connected()){
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
- if((target_info = client_context_tmp->target_info) == NULL){
- return NET_NFC_NO_DATA_FOUND;
- }
- if((target_info = client_context_tmp->target_info) == NULL){
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
- data_h UID = NULL;
-
- if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){
+ if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ JEWEL_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
return NET_NFC_NO_DATA_FOUND;
}
- if(((data_s*)UID)->length != 4){
-
+ if(((data_s*)UID)->length != 4)
return NET_NFC_OUT_OF_BOUND;
- }
-
-
- uint8_t send_buffer[9] = {0x00, };
/* command */
send_buffer[0] = JEWEL_CMD_WRITE_E;
send_buffer[2] = data;
/* UID0 ~ 3 */
- memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length);
+ memcpy(&(send_buffer[3]),
+ ((data_s*)UID)->buffer,
+ ((data_s*)UID)->length);
net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 9;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_jewel_write_with_no_erase (net_nfc_target_handle_h handle, uint8_t block, uint8_t byte, uint8_t data, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_jewel_write_with_no_erase(
+ net_nfc_target_handle_h handle,
+ uint8_t block,
+ uint8_t byte,
+ uint8_t data,
+ nfc_transceive_callback callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t send_buffer[9] = {0x00, };
+
if(handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if(block > 0xE || byte > 0x7 ){
-
+ if(block > 0xE || byte > 0x7 )
return NET_NFC_OUT_OF_BOUND;
- }
- if(!net_nfc_tag_is_connected()){
+ if(net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* client_context_tmp = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
- if((target_info = client_context_tmp->target_info) == NULL){
+ target_info = net_nfc_client_tag_get_client_target_info();
+ if (target_info == NULL)
return NET_NFC_NO_DATA_FOUND;
- }
- if(target_info->devType != NET_NFC_JEWEL_PICC){
+ if(target_info->devType != NET_NFC_JEWEL_PICC)
+ {
DEBUG_CLIENT_MSG("only Jewel tag is available");
return NET_NFC_NOT_ALLOWED_OPERATION;
}
- data_h UID = NULL;
-
- if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, JEWEL_TAG_KEY, &UID) != NET_NFC_OK){
+ if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ JEWEL_TAG_KEY,
+ &UID) != NET_NFC_OK)
+ {
return NET_NFC_NO_DATA_FOUND;
}
- if(((data_s*)UID)->length != 4){
-
+ if(((data_s*)UID)->length != 4)
return NET_NFC_OUT_OF_BOUND;
- }
-
- uint8_t send_buffer[9] = {0x00, };
/* command */
send_buffer[0] = JEWEL_CMD_WRITE_NE;
send_buffer[2] = data;
/* UID0 ~ 3 */
- memcpy(&(send_buffer[3]), ((data_s*)UID)->buffer, ((data_s*)UID)->length);
+ memcpy(&(send_buffer[3]),
+ ((data_s*)UID)->buffer,
+ ((data_s*)UID)->length);
net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 9;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
-
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <glib.h>
+#include <string.h>
+
+#include "net_nfc_client_transceive.h"
+#include "net_nfc_client_tag_internal.h"
-#include "net_nfc_tag.h"
-#include "net_nfc_data.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_client_ipc_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_client_nfc_private.h"
#include "net_nfc_tag_mifare.h"
-#include "net_nfc_target_info.h"
-#include "net_nfc_util_private.h"
-#include <string.h>
+#include "net_nfc_data.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_util_internal.h"
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
#endif
#define MIFARE_CMD_RAW 0x00U
-#define MIFARE_CMD_AUTH_A 0x60U /**< authenticate with key A */
-#define MIFARE_CMD_AUTH_B 0x61U /**< authenticate with key B */
-#define MIFARE_CMD_READ 0x30U /**< read 16 bytes */
-#define MIFARE_CMD_WRITE_BLOCK 0xA0U /**< write 16 bytes */
-#define MIFARE_CMD_WRITE_PAGE 0xA2U /**< write 4 bytes */
-#define MIFARE_CMD_INCREMENT 0xC1U /**< Increment. */
-#define MIFARE_CMD_DECREMENT 0xC0U /**< Decrement. */
-#define MIFARE_CMD_TRANSFER 0xB0U /**< Tranfer. */
-#define MIFARE_CMD_RESTORE 0xC2U /**< Restore. */
+#define MIFARE_CMD_AUTH_A 0x60U /**< authenticate with key A */
+#define MIFARE_CMD_AUTH_B 0x61U /**< authenticate with key B */
+#define MIFARE_CMD_READ 0x30U /**< read 16 bytes */
+#define MIFARE_CMD_WRITE_BLOCK 0xA0U /**< write 16 bytes */
+#define MIFARE_CMD_WRITE_PAGE 0xA2U /**< write 4 bytes */
+#define MIFARE_CMD_INCREMENT 0xC1U /**< Increment. */
+#define MIFARE_CMD_DECREMENT 0xC0U /**< Decrement. */
+#define MIFARE_CMD_TRANSFER 0xB0U /**< Tranfer. */
+#define MIFARE_CMD_RESTORE 0xC2U /**< Restore. */
#define MIFARE_TAG_KEY "UID"
#define MIFARE_CMD_READ_SECTOR 0x38U /* read sector */
#define MIFARE_1K_SECTORS 16
#define MIFARE_4K_SECTORS 40
-#define MIFARE_BLOCK_SIZE 16 /* 1 block is 16 byte */
-#define MIFARE_PAGE_SIZE 4 /* 1 page is 4 byte */
+#define MIFARE_BLOCK_SIZE 16 /* 1 block is 16 byte */
+#define MIFARE_PAGE_SIZE 4 /* 1 page is 4 byte */
+
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_authenticate_with_keyA(net_nfc_target_handle_h handle, uint8_t sector, data_h auth_key, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyA(
+ net_nfc_target_handle_h handle,
+ uint8_t sector,
+ data_h auth_key,
+ void *callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s *key;
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int send_buffer_length = 0;
+
+ uint8_t sector_to_block = 0;
+
+
if (handle == NULL || auth_key == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
- data_s* key = (data_s*)auth_key;
+ key = (data_s *)auth_key;
if (key->length != 6)
- {
return NET_NFC_OUT_OF_BOUND;
- }
-
- client_context_t* tmp_client_context = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
+ target_info = net_nfc_client_tag_get_client_target_info();
- if (tmp_client_context != NULL)
+ if (target_info)
{
-
- target_info = tmp_client_context->target_info;
-
- if (target_info != NULL)
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
{
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG \n");
- return NET_NFC_NOT_SUPPORTED;
- }
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG");
+ return NET_NFC_NOT_SUPPORTED;
}
}
- data_h UID = NULL;
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, MIFARE_TAG_KEY, &UID) != NET_NFC_OK)
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ MIFARE_TAG_KEY,
+ &UID) != NET_NFC_OK)
{
return NET_NFC_NO_DATA_FOUND;
}
- uint8_t* send_buffer = NULL;
- int send_buffer_length = 0;
-
- uint8_t sector_to_block = 0;
-
switch (target_info->devType)
{
case NET_NFC_MIFARE_MINI_PICC :
{
/* 0 ~ 4 : 5 sector and 4 block with 16 bytes */
if (sector > MIFARE_MINI_SECTORS - 1)
- {
-
return NET_NFC_OUT_OF_BOUND;
- }
- else
- {
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
}
break;
case NET_NFC_MIFARE_1K_PICC :
{
/* 0 ~ 15 : 16 sector and 4 block with 16 bytes */
if (sector > MIFARE_1K_SECTORS)
- {
-
return NET_NFC_OUT_OF_BOUND;
- }
- else
- {
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
}
break;
case NET_NFC_MIFARE_4K_PICC :
* 32 ~ 39 : 8 sector and 16 block with 16 bytes
*/
if (sector > MIFARE_4K_SECTORS)
- {
-
return NET_NFC_OUT_OF_BOUND;
- }
+
+ if (sector < 32)
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
else
{
-
- if (sector < 32)
- {
-
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
- else
- {
-
- sector_to_block = (31 * MIFARE_BLOCK_4 + 3) + (sector - 32) * MIFARE_BLOCK_16 + 15;
- }
+ sector_to_block = (31 * MIFARE_BLOCK_4 + 3)
+ + (sector - 32)
+ * MIFARE_BLOCK_16 + 15;
}
}
break;
break;
}
- uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + ((data_s*)UID)->length + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ /* cmd + addr + UID + AUTH_KEY + CRC_A */
+ send_buffer_length = 1 + 1 + ((data_s*)UID)->length
+ + key->length + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
{
-
net_nfc_free_data(UID);
return NET_NFC_ALLOC_FAIL;
}
net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
- data_s rawdata;
rawdata.buffer = send_buffer;
rawdata.length = send_buffer_length;
- net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ net_nfc_error_e result = net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
if (send_buffer != NULL)
- {
-
_net_nfc_util_free_mem(send_buffer);
- }
return result;
-
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_authenticate_with_keyB(net_nfc_target_handle_h handle, uint8_t sector, data_h auth_key, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB(
+ net_nfc_target_handle_h handle,
+ uint8_t sector,
+ data_h auth_key,
+ void *callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s *key;
+ data_s rawdata;
+
+ data_h UID = NULL;
+
+ uint8_t* send_buffer = NULL;
+ uint8_t* temp = NULL;
+
+ int send_buffer_length = 0;
+
+ uint8_t sector_to_block = 0;
+
+
if (handle == NULL || auth_key == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
- data_s* key = (data_s*)auth_key;
+ key = (data_s *)auth_key;
if (key->length != 6)
- {
return NET_NFC_OUT_OF_BOUND;
- }
- client_context_t* tmp_client_context = net_nfc_get_client_context();
-
- net_nfc_target_info_s* target_info = NULL;
+ target_info = net_nfc_client_tag_get_client_target_info();
- if (tmp_client_context != NULL)
+ if (target_info != NULL)
{
-
- target_info = tmp_client_context->target_info;
-
- if (target_info != NULL)
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
{
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG \n");
- return NET_NFC_NOT_SUPPORTED;
- }
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG");
+ return NET_NFC_NOT_SUPPORTED;
}
}
- data_h UID = NULL;
-
- if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info, MIFARE_TAG_KEY, &UID) != NET_NFC_OK)
+ if (net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
+ MIFARE_TAG_KEY,
+ &UID) != NET_NFC_OK)
{
return NET_NFC_NO_DATA_FOUND;
}
- uint8_t* send_buffer = NULL;
- int send_buffer_length = 0;
-
- uint8_t sector_to_block = 0;
-
switch (target_info->devType)
{
case NET_NFC_MIFARE_MINI_PICC :
{
/* 0 ~ 4 : 5 sector and 4 block with 16 bytes */
if (sector > MIFARE_MINI_SECTORS)
- {
return NET_NFC_OUT_OF_BOUND;
- }
- else
- {
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
+
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
}
break;
case NET_NFC_MIFARE_1K_PICC :
{
/* 0 ~ 15 : 16 sector and 4 block with 16 bytes */
if (sector > MIFARE_1K_SECTORS)
- {
return NET_NFC_OUT_OF_BOUND;
- }
- else
- {
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
+
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
}
break;
case NET_NFC_MIFARE_4K_PICC :
* 32 ~ 39 : 8 sector and 16 block with 16 bytes
*/
if (sector > MIFARE_4K_SECTORS)
- {
return NET_NFC_OUT_OF_BOUND;
- }
+
+ if (sector < 32)
+ sector_to_block = sector * MIFARE_BLOCK_4 + 3;
else
{
- if (sector < 32)
- {
- sector_to_block = sector * MIFARE_BLOCK_4 + 3;
- }
- else
- {
- sector_to_block = (31 * MIFARE_BLOCK_4 + 3) + (sector - 32) * MIFARE_BLOCK_16 + 15;
- }
+ sector_to_block = (31 * MIFARE_BLOCK_4 + 3)
+ + (sector - 32)
+ * MIFARE_BLOCK_16 + 15;
}
}
break;
break;
}
- uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + ((data_s*)UID)->length + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */
+ send_buffer_length = 1 + 1 + ((data_s*)UID)->length
+ + key->length + 2; /* cmd + addr + UID + AUTH_KEY + CRC_A */
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer, send_buffer_length
+ * sizeof(uint8_t));
if (send_buffer == NULL)
{
-
net_nfc_free_data(UID);
return NET_NFC_ALLOC_FAIL;
}
net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = send_buffer_length;
- net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ net_nfc_error_e result = net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
if (send_buffer != NULL)
- {
_net_nfc_util_free_mem(send_buffer);
- }
return result;
-
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_read(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_read(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[4] = { 0 };
+
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* tmp_client_context = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
+ target_info = net_nfc_client_tag_get_client_target_info();
- if (tmp_client_context != NULL)
+ if (target_info != NULL)
{
-
- target_info = tmp_client_context->target_info;
-
- if (target_info != NULL)
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
{
+ DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d]",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
-
- if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
- {
-
- if (addr > 7)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
- }
+ if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ if (addr > 7)
+ return NET_NFC_OUT_OF_BOUND;
}
}
- uint8_t send_buffer[4] = { 0 };
send_buffer[0] = MIFARE_CMD_READ;
send_buffer[1] = addr;
net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 4;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive_data(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_write_block(net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_write_block(
+ net_nfc_target_handle_h handle,
+ uint8_t addr,
+ data_h data,
+ void *callback,
+ void *user_data)
{
- if (handle == NULL)
- return NET_NFC_NULL_PARAMETER;
+ net_nfc_target_info_s* target_info = NULL;
- if (!net_nfc_tag_is_connected())
- {
- return NET_NFC_OPERATION_FAIL;
- }
+ data_s rawdata;
- client_context_t* tmp_client_context = net_nfc_get_client_context();
+ uint8_t* send_buffer = NULL;
- net_nfc_target_info_s* target_info = NULL;
+ uint32_t send_buffer_length = 0;
- if (tmp_client_context != NULL)
- {
- target_info = tmp_client_context->target_info;
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
- if (target_info != NULL)
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
- if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
- {
+ target_info = net_nfc_client_tag_get_client_target_info();
- if (addr > 7)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
- }
- }
- else
- {
- return NET_NFC_NOT_INITIALIZED;
- }
- }
- else
- {
+ if (target_info == NULL)
return NET_NFC_NOT_INITIALIZED;
- }
- uint8_t* send_buffer = NULL;
- uint32_t send_buffer_length = 0;
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d] \n",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
+ }
if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
{
+ if (addr > 7)
+ return NET_NFC_OUT_OF_BOUND;
+ }
- if (((data_s*)data)->length > MIFARE_PAGE_SIZE)
+ if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
+ {
+ if (((data_s *)data)->length > MIFARE_PAGE_SIZE)
{
+ uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
- uint8_t* temp = NULL;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
return NET_NFC_ALLOC_FAIL;
*temp = addr;
temp++;
- memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE);
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ MIFARE_PAGE_SIZE);
}
else
{
+ uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 +
+ ((data_s*)data)->length + 2;
- uint8_t* temp = NULL;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
return NET_NFC_ALLOC_FAIL;
*temp = addr;
temp++;
- memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length);
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ ((data_s*)data)->length);
}
}
if (((data_s*)data)->length > MIFARE_BLOCK_SIZE)
{
+ uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + MIFARE_BLOCK_SIZE + 2; /* cmd + addr + page + CRC */
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + MIFARE_BLOCK_SIZE + 2;
- uint8_t* temp = NULL;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
return NET_NFC_ALLOC_FAIL;
*temp = addr;
temp++;
- memcpy(temp, ((data_s*)data)->buffer, MIFARE_BLOCK_SIZE);
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ MIFARE_BLOCK_SIZE);
}
else
{
- send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */
-
uint8_t* temp = NULL;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + ((data_s*)data)->length
+ + 2;
+
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
return NET_NFC_ALLOC_FAIL;
*temp = addr;
temp++;
- memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length);
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ ((data_s*)data)->length);
}
}
net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = send_buffer_length;
- net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ net_nfc_error_e result = net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
if (send_buffer != NULL)
_net_nfc_util_free_mem(send_buffer);
return result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_write_page(net_nfc_target_handle_h handle, uint8_t addr, data_h data, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_write_page(
+ net_nfc_target_handle_h handle,
+ uint8_t addr,
+ data_h data,
+ void *callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ uint8_t* send_buffer = NULL;
+
+ uint32_t send_buffer_length = 0;
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
- client_context_t* tmp_client_context = net_nfc_get_client_context();
+ target_info = net_nfc_client_tag_get_client_target_info();
- net_nfc_target_info_s* target_info = NULL;
+ if (target_info == NULL)
+ return NET_NFC_NOT_INITIALIZED;
- if (tmp_client_context != NULL)
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
{
-
- target_info = tmp_client_context->target_info;
-
- if (target_info != NULL)
- {
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_ULTRA_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE TAG = [%d] \n", target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
-
- if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
- {
-
- if (addr > 7)
- {
- return NET_NFC_OUT_OF_BOUND;
- }
- }
- }
- else
- {
- return NET_NFC_NOT_INITIALIZED;
- }
+ DEBUG_CLIENT_MSG("not a MIFARE TAG = [%d] \n",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
}
- else
+
+ if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
{
- return NET_NFC_NOT_INITIALIZED;
+ if (addr > 7)
+ return NET_NFC_OUT_OF_BOUND;
}
- uint8_t* send_buffer = NULL;
- uint32_t send_buffer_length = 0;
-
if (target_info->devType == NET_NFC_MIFARE_ULTRA_PICC)
{
-
if (((data_s*)data)->length > MIFARE_PAGE_SIZE)
{
+ uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
- uint8_t* temp = NULL;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
return NET_NFC_ALLOC_FAIL;
*temp = addr;
temp++;
- memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE);
-
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ MIFARE_PAGE_SIZE);
}
else
{
+ uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + ((data_s*)data)->length
+ + 2;
- uint8_t* temp = NULL;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
return NET_NFC_ALLOC_FAIL;
*temp = addr;
temp++;
- memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length);
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ ((data_s*)data)->length);
}
}
else
{
-
if (((data_s*)data)->length > MIFARE_PAGE_SIZE)
{
+ uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2; /* cmd + addr + page + CRC */
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + MIFARE_PAGE_SIZE + 2;
- uint8_t* temp = NULL;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
return NET_NFC_ALLOC_FAIL;
*temp = addr;
temp++;
- memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE);
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ MIFARE_PAGE_SIZE);
}
else
{
+ uint8_t* temp = NULL;
- send_buffer_length = 1 + 1 + ((data_s*)data)->length + 2; /* cmd + addr + page + CRC */
+ /* cmd + addr + page + CRC */
+ send_buffer_length = 1 + 1 + ((data_s*)data)->length
+ + 2;
- uint8_t* temp = NULL;
- _net_nfc_util_alloc_mem(send_buffer, send_buffer_length * sizeof(uint8_t));
+ _net_nfc_util_alloc_mem(send_buffer,
+ send_buffer_length * sizeof(uint8_t));
if (send_buffer == NULL)
return NET_NFC_ALLOC_FAIL;
*temp = addr;
temp++;
- memcpy(temp, ((data_s*)data)->buffer, ((data_s*)data)->length);
+ memcpy(temp,
+ ((data_s*)data)->buffer,
+ ((data_s*)data)->length);
}
}
rawdata.buffer = send_buffer;
rawdata.length = send_buffer_length;
- net_nfc_error_e result = net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ net_nfc_error_e result = net_nfc_client_transceive(handle,
+ (data_h)&rawdata,
+ callback,
+ user_data);
if (send_buffer != NULL)
_net_nfc_util_free_mem(send_buffer);
return result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_increment(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_increment(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ int value,
+ void *callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[8] = { 0 };
+
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* tmp_client_context = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
+ target_info = net_nfc_client_tag_get_client_target_info();
- if (tmp_client_context != NULL)
+ if (target_info)
{
-
- target_info = tmp_client_context->target_info;
-
- if (target_info != NULL)
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
{
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
+ DEBUG_CLIENT_MSG(
+ "not a MIFARE Classic TAG = [%d]",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
}
}
- uint8_t send_buffer[8] = { 0 };
send_buffer[0] = MIFARE_CMD_INCREMENT;
send_buffer[1] = addr;
- /* little endian. little value of byte array will be saved first in memory */
+ /* little endian.
+ little value of byte array will be saved first in memory */
send_buffer[5] = (value & 0xFF000000) >> 24;
send_buffer[4] = (value & 0x00FF0000) >> 16;
send_buffer[3] = (value & 0x0000FF00) >> 8;
net_nfc_util_compute_CRC(CRC_A, send_buffer, 8);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 8;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_decrement(net_nfc_target_handle_h handle, uint8_t addr, int value, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_decrement(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ int value,
+ void *callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[8] = { 0 };
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
-
- client_context_t* tmp_client_context = net_nfc_get_client_context();
- net_nfc_target_info_s* target_info = NULL;
+ target_info = net_nfc_client_tag_get_client_target_info();
- if (tmp_client_context != NULL)
+ if (target_info)
{
- target_info = tmp_client_context->target_info;
-
- if (target_info != NULL)
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
{
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d] \n",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
}
}
- uint8_t send_buffer[8] = { 0 };
-
send_buffer[0] = MIFARE_CMD_DECREMENT;
send_buffer[1] = addr;
- // little endian. little value of byte array will be saved first in memory
+ /* little endian.
+ little value of byte array will be saved first in memory */
send_buffer[5] = (value & 0xFF000000) >> 24;
send_buffer[4] = (value & 0x00FF0000) >> 16;
send_buffer[3] = (value & 0x0000FF00) >> 8;
DEBUG_MSG_PRINT_BUFFER(send_buffer, 8);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 8;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
-
+ return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_transfer(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[4] = { 0 };
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
- client_context_t* tmp_client_context = net_nfc_get_client_context();
-
- net_nfc_target_info_s* target_info = NULL;
+ target_info = net_nfc_client_tag_get_client_target_info();
- if (tmp_client_context != NULL)
+ if (target_info)
{
-
- target_info = tmp_client_context->target_info;
-
- if (target_info != NULL)
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
{
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d]",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
}
}
- uint8_t send_buffer[4] = { 0 };
-
send_buffer[0] = MIFARE_CMD_TRANSFER;
send_buffer[1] = addr;
net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 4;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
-
+ return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_restore(net_nfc_target_handle_h handle, uint8_t addr, void* trans_param)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_restore(net_nfc_target_handle_h handle,
+ uint8_t addr,
+ void *callback,
+ void *user_data)
{
+ net_nfc_target_info_s* target_info = NULL;
+
+ data_s rawdata;
+
+ uint8_t send_buffer[4] = { 0 };
+
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (!net_nfc_tag_is_connected())
- {
+ if (net_nfc_client_tag_is_connected() == FALSE)
return NET_NFC_OPERATION_FAIL;
- }
- client_context_t* tmp_client_context = net_nfc_get_client_context();
-
- net_nfc_target_info_s* target_info = NULL;
+ target_info = net_nfc_client_tag_get_client_target_info();
- if (tmp_client_context != NULL)
+ if (target_info)
{
-
- target_info = tmp_client_context->target_info;
-
- if (target_info != NULL)
+ if (target_info->devType < NET_NFC_MIFARE_MINI_PICC ||
+ target_info->devType > NET_NFC_MIFARE_4K_PICC)
{
-
- if (target_info->devType < NET_NFC_MIFARE_MINI_PICC || target_info->devType > NET_NFC_MIFARE_4K_PICC)
- {
- DEBUG_CLIENT_MSG("This is not MIFARE Classic TAG = [%d] \n", target_info->devType);
- return NET_NFC_NOT_SUPPORTED;
- }
+ DEBUG_CLIENT_MSG("not a MIFARE Classic TAG = [%d]",
+ target_info->devType);
+ return NET_NFC_NOT_SUPPORTED;
}
}
- uint8_t send_buffer[4] = { 0 };
-
send_buffer[0] = MIFARE_CMD_RESTORE;
send_buffer[1] = addr;
net_nfc_util_compute_CRC(CRC_A, send_buffer, 4);
- data_s rawdata;
-
rawdata.buffer = send_buffer;
rawdata.length = 4;
- return net_nfc_transceive(handle, (data_h)&rawdata, trans_param);
+ return net_nfc_client_transceive(handle, (data_h)&rawdata, callback,
+ user_data);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_default_key(data_h* key)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_create_default_key(data_h* key)
{
if (key == NULL)
return NET_NFC_NULL_PARAMETER;
return net_nfc_create_data(key, default_key, 6);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_application_directory_key(data_h* key)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_create_application_directory_key(
+ data_h* key)
{
if (key == NULL)
return NET_NFC_NULL_PARAMETER;
return net_nfc_create_data(key, mad_key, 6);
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_mifare_create_net_nfc_forum_key(data_h* key)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_mifare_create_net_nfc_forum_key(data_h* key)
{
if (key == NULL)
return NET_NFC_NULL_PARAMETER;
#include <stdbool.h>
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
#include "net_nfc_data.h"
#include "net_nfc_target_info.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info;
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
- *type = target_info_private->devType;
+ *type = tmp_target_info->devType;
return NET_NFC_OK;
}
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info;
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
- *handle = (net_nfc_target_handle_h)target_info_private->handle;
+ *handle = (net_nfc_target_handle_h)tmp_target_info->handle;
return NET_NFC_OK;
}
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info;
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
- *is_support = (bool)target_info_private->is_ndef_supported;
+ *is_support = (bool)tmp_target_info->is_ndef_supported;
return NET_NFC_OK;
}
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info;
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
- *max_size = target_info_private->maxDataSize;
+ *max_size = tmp_target_info->maxDataSize;
return NET_NFC_OK;
}
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_target_info_s * target_info_private = (net_nfc_target_info_s*)target_info;
+ net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info;
- *actual_data = target_info_private->actualDataSize;
+ *actual_data = tmp_target_info->actualDataSize;
return NET_NFC_OK;
}
}
}
- if (handle->raw_data.buffer != NULL && handle->raw_data.length > 0)
+ if (handle->raw_data.length > 0)
{
net_nfc_util_alloc_data(&temp->raw_data, handle->raw_data.length);
memcpy(temp->raw_data.buffer, handle->raw_data.buffer, temp->raw_data.length);
return NET_NFC_OK;
}
-net_nfc_error_e net_nfc_util_release_tag_info(net_nfc_target_info_s *info)
+static net_nfc_error_e net_nfc_util_release_tag_info(net_nfc_target_info_s *info)
{
net_nfc_error_e result = NET_NFC_OK;
net_nfc_tag_info_s *list = NULL;
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "net_nfc.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_client_ipc_private.h"
-
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_test.h"
#ifndef NET_NFC_EXPORT_API
#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
#endif
-NET_NFC_EXPORT_API void net_nfc_test_read_test_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+typedef struct _TestFuncData TestFuncData;
+
+struct _TestFuncData
+{
+ gpointer callback;
+ gpointer user_data;
+};
+
+static void test_call_sim_test_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void test_call_prbs_test_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void test_call_get_firmware_version_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void test_call_set_ee_data_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static NetNfcGDbusTest *test_proxy = NULL;
+
+
+static void test_call_sim_test_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_test_sim_test_completed callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_test_call_sim_test_finish(
+ NET_NFC_GDBUS_TEST(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish sim_test: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_test_sim_test_completed)func_data->callback;
+ data = func_data->user_data;
+
+ callback(out_result, data);
+
+ g_free(func_data);
+}
+
+static void test_call_prbs_test_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ net_nfc_client_test_prbs_test_completed callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_test_call_prbs_test_finish(
+ NET_NFC_GDBUS_TEST(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish prbs test: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_test_prbs_test_completed)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(out_result, data);
+
+ g_free(func_data);
+}
+
+static void test_call_get_firmware_version_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ gchar *out_version = NULL;
+ GError *error = NULL;
+
+ net_nfc_client_test_get_firmware_version_completed callback;
+ gpointer data;
+
+ if (net_nfc_gdbus_test_call_get_firmware_version_finish(
+ NET_NFC_GDBUS_TEST(source_object),
+ (gint *)&out_result,
+ &out_version,
+ res,
+ &error) == FALSE)
+ {
+
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish get_firmware_version: %s",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+ if (func_data == NULL)
+ return;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(out_version);
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_test_get_firmware_version_completed)
+ func_data->callback;
+ data = func_data->user_data;
+
+ callback(out_result, out_version, data);
+
+ g_free(out_version);
+ g_free(func_data);
+}
+
+static void test_call_set_ee_data_callback(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ GError *error = NULL;
+
+ net_nfc_client_test_set_ee_data_completed callback;
+
+ if (net_nfc_gdbus_test_call_set_ee_data_finish(
+ NET_NFC_GDBUS_TEST(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish set_ee_data: %s\n",
+ error->message);
+ g_error_free(error);
+ }
+
+ func_data = user_data;
+
+ if (func_data->callback == NULL)
+ {
+ g_free(func_data);
+ return;
+ }
+
+ callback = (net_nfc_client_test_set_ee_data_completed)
+ func_data->callback;
+
+ callback(out_result, func_data->user_data);
+
+ g_free(func_data);
+}
+
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_test_sim_test(
+ net_nfc_client_test_sim_test_completed callback,
+ void *user_data)
{
- DEBUG_CLIENT_MSG("user_param = [%p] trans_param = [%p] , message[%d]", user_param, trans_data, message);
+ TestFuncData *func_data;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TestFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_test_call_sim_test(test_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ test_call_sim_test_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
- switch (message)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_test_sim_test_sync(void)
+{
+ GError *error = NULL;
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_test_call_sim_test_sync(test_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
{
- case NET_NFC_MESSAGE_TAG_DISCOVERED :
- {
- if (result == NET_NFC_OK)
- {
- DEBUG_CLIENT_MSG("net_nfc_test_read_cb SUCCESS!!!!! [%d ]", result);
- }
- else
- {
- DEBUG_CLIENT_MSG("net_nfc_test_read_cb FAIL!!!!![%d]", result);
- }
- }
- break;
-
- default :
- break;
+ DEBUG_CLIENT_MSG("can not call SimTest: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
+
+ return out_result;
}
-NET_NFC_EXPORT_API void net_nfc_test_sim_test_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_test_prbs_test(uint32_t tech,
+ uint32_t rate,
+ net_nfc_client_test_prbs_test_completed callback,
+ void *user_data)
{
- DEBUG_CLIENT_MSG("user_param = [%p] trans_param = [%p] data = [%p]", user_param, trans_data, data);
+ TestFuncData *func_data;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TestFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_test_call_prbs_test(test_proxy,
+ tech,
+ rate,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ test_call_prbs_test_callback,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_test_prbs_test_sync(uint32_t tech,
+ uint32_t rate)
+{
+ GError *error = NULL;
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
- switch (message)
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_test_call_prbs_test_sync(test_proxy,
+ tech,
+ rate,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
{
- case NET_NFC_MESSAGE_SIM_TEST :
- {
- if (result == NET_NFC_OK)
- {
- DEBUG_CLIENT_MSG("net_nfc_test_sim_test_cb SUCCESS!!!!! [%d]", result);
- }
- else
- {
- DEBUG_CLIENT_MSG("net_nfc_test_sim_test_cb FAIL!!!!![%d]", result);
- }
- }
- break;
-
- default :
- break;
+ DEBUG_CLIENT_MSG("can not call PrbsTest: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
+
+ return out_result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_sim_test(void)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_test_get_firmware_version(
+ net_nfc_client_test_get_firmware_version_completed callback,
+ void *user_data)
{
- net_nfc_error_e ret;
- net_nfc_request_test_t request = { 0, };
+ TestFuncData *func_data;
- request.length = sizeof(net_nfc_request_test_t);
- request.request_type = NET_NFC_MESSAGE_SIM_TEST;
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ func_data = g_new0(TestFuncData, 1);
+ if (func_data == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
- return ret;
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_test_call_get_firmware_version(test_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ test_call_get_firmware_version_callback,
+ func_data);
+
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_prbs_test(int tech, int rate)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_test_get_firmware_version_sync(char **version)
{
- net_nfc_error_e ret;
- net_nfc_request_test_t request = { 0, };
+ gchar *out_version = NULL;
+ GError *error = NULL;
- request.length = sizeof(net_nfc_request_test_t);
- request.request_type = NET_NFC_MESSAGE_PRBS_TEST;/*TEST MODE*/
- request.rate = rate;
- request.tech = tech;
+ net_nfc_error_e out_result = NET_NFC_OK;
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- return ret;
+ if (net_nfc_gdbus_test_call_get_firmware_version_sync(test_proxy,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)out_result,
+ &out_version,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_CLIENT_MSG("can not call PrbsTest: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (version != NULL)
+ *version = out_version;
+
+ return out_result;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_firmware_version(void)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_test_set_ee_data(int mode,
+ int reg_id,
+ data_h data,
+ net_nfc_client_test_set_ee_data_completed callback,
+ void *user_data)
{
- net_nfc_error_e ret;
- net_nfc_request_msg_t request = { 0, };
+ TestFuncData *func_data;
+ GVariant *variant = NULL;
+
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(TestFuncData, 1);
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
- request.length = sizeof(net_nfc_request_msg_t);
- request.request_type = NET_NFC_MESSAGE_GET_FIRMWARE_VERSION;
+ variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)&request, NULL);
+ net_nfc_gdbus_test_call_set_ee_data(test_proxy,
+ mode,
+ reg_id,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ test_call_set_ee_data_callback,
+ func_data);
- return ret;
+ return NET_NFC_OK;
}
-NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_eedata_register(int mode, int reg_id, uint8_t *data, uint32_t len)
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_test_set_ee_data_sync(int mode,
+ int reg_id,
+ data_h data)
{
- net_nfc_request_eedata_register_t *request = NULL;
- net_nfc_error_e result;
- uint32_t length = 0;
+ GVariant *variant = NULL;
+ GError *error = NULL;
- DEBUG_CLIENT_MSG("net_nfc_set_eedata_register");
+ net_nfc_error_e out_result = NET_NFC_OK;
- length = sizeof(net_nfc_request_eedata_register_t) + len;
+ if (test_proxy == NULL)
+ return NET_NFC_UNKNOWN_ERROR;
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant((data_s *)data);
+
+ if (net_nfc_gdbus_test_call_set_ee_data_sync(test_proxy,
+ mode,
+ reg_id,
+ variant,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
{
- return NET_NFC_ALLOC_FAIL;
+ DEBUG_CLIENT_MSG("can not call SetEeTest: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
}
- /* fill request message */
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_SET_EEDATA;
- request->mode = mode;
- request->reg_id = reg_id;
- request->data.length = len;
- memcpy(request->data.buffer, data, len);
+ return out_result;
+}
- result = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
+net_nfc_error_e net_nfc_client_test_init(void)
+{
+ GError *error = NULL;
+
+ if (test_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
- _net_nfc_util_free_mem(request);
+ test_proxy = net_nfc_gdbus_test_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Test",
+ NULL,
+ &error);
- return result;
+ if (test_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
}
+void net_nfc_client_test_deinit(void)
+{
+ if (test_proxy)
+ {
+ g_object_unref(test_proxy);
+ test_proxy = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_client.h"
+#include "net_nfc_client_manager.h"
+#include "net_nfc_client_tag_internal.h"
+#include "net_nfc_client_transceive.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+static NetNfcGDbusTransceive *transceive_proxy = NULL;
+
+static GVariant *transceive_data_to_transceive_variant(
+ net_nfc_target_type_e dev_type,
+ data_s *data);
+
+static void transceive_call(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+static void transceive_data_call(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data);
+
+typedef struct _TransceiveFuncData TransceiveFuncData;
+
+struct _TransceiveFuncData
+{
+ gpointer transceive_send_callback;
+ gpointer transceive_send_data;
+};
+
+static GVariant *transceive_data_to_transceive_variant(
+ net_nfc_target_type_e devType,
+ data_s *data)
+{
+ GVariant *variant = NULL;
+ data_s transceive_info = {NULL,};
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is empty");
+ return NULL;
+ }
+
+ switch (devType)
+ {
+ case NET_NFC_MIFARE_MINI_PICC :
+ case NET_NFC_MIFARE_1K_PICC :
+ case NET_NFC_MIFARE_4K_PICC :
+ case NET_NFC_MIFARE_ULTRA_PICC :
+ {
+ if(net_nfc_util_alloc_data(&transceive_info,
+ data->length + 2) == true)
+ {
+ memcpy(transceive_info.buffer,
+ data->buffer,
+ data->length);
+
+ net_nfc_util_compute_CRC(CRC_A,
+ transceive_info.buffer,
+ transceive_info.length);
+ }
+ }
+ break;
+
+ case NET_NFC_JEWEL_PICC :
+ {
+ if (data->length > 9)
+ {
+ DEBUG_ERR_MSG("data length is larger than 9");
+ return NULL;
+ }
+
+ if(net_nfc_util_alloc_data(&transceive_info, 9) == true)
+ {
+ memcpy(transceive_info.buffer,
+ data->buffer,
+ data->length);
+ net_nfc_util_compute_CRC(CRC_B,
+ transceive_info.buffer,
+ transceive_info.length);
+ }
+
+ }
+ break;
+
+ default :
+ {
+ if(net_nfc_util_alloc_data(&transceive_info,
+ data->length) == true)
+ {
+ memcpy(transceive_info.buffer,
+ data->buffer,
+ data->length);
+ }
+ }
+ break;
+ }
+
+ variant = net_nfc_util_gdbus_data_to_variant(&transceive_info);
+
+ net_nfc_util_free_data(&transceive_info);
+
+ return variant;
+}
+
+static void transceive_data_call(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TransceiveFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ GVariant *out_data = NULL;
+
+ data_s resp = {NULL,};
+
+ if(net_nfc_gdbus_transceive_call_transceive_data_finish(
+ NET_NFC_GDBUS_TRANSCEIVE(source_object),
+ (gint *)&out_result,
+ &out_data,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish transceive: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (TransceiveFuncData*) user_data;
+ if(func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get TransceiveFuncData");
+ return;
+ }
+
+ if(func_data->transceive_send_callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ net_nfc_util_gdbus_variant_to_data_s(out_data, &resp);
+
+ ((nfc_transceive_data_callback)func_data->transceive_send_callback)(
+ out_result,
+ &resp,
+ func_data->transceive_send_data);
+
+ net_nfc_util_free_data(&resp);
+
+ g_free(func_data);
+}
+
+static void transceive_call(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TransceiveFuncData *func_data;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+ GError *error = NULL;
+
+ if(net_nfc_gdbus_transceive_call_transceive_finish(
+ NET_NFC_GDBUS_TRANSCEIVE(source_object),
+ (gint *)&out_result,
+ res,
+ &error) == FALSE)
+ {
+ out_result = NET_NFC_UNKNOWN_ERROR;
+
+ DEBUG_ERR_MSG("Can not finish transceive: %s", error->message);
+ g_error_free(error);
+ }
+
+ func_data = (TransceiveFuncData*) user_data;
+ if(func_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get TransceiveFuncData");
+ return;
+ }
+
+ if(func_data->transceive_send_callback == NULL)
+ {
+ DEBUG_CLIENT_MSG("callback function is not avaiilable");
+ g_free(func_data);
+ return;
+ }
+
+ ((nfc_transceive_callback)func_data->transceive_send_callback)(
+ out_result,
+ func_data->transceive_send_data);
+
+ g_free(func_data);
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle,
+ data_h rawdata,
+ nfc_transceive_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s *target_info = NULL;
+ data_s *data = (data_s *)rawdata;
+
+ GVariant *arg_data = NULL;
+ TransceiveFuncData *funcdata = NULL;
+
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get TransceiveProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+
+ if (handle == NULL || rawdata == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ /* fill trans information struct */
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = transceive_data_to_transceive_variant(target_info->devType,
+ data);
+ if (arg_data == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ funcdata = g_new0(TransceiveFuncData, 1);
+
+ funcdata->transceive_send_callback = (gpointer)callback;
+ funcdata->transceive_send_data = user_data;
+
+ net_nfc_gdbus_transceive_call_transceive(transceive_proxy,
+ GPOINTER_TO_UINT(handle),
+ target_info->devType,
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ transceive_call,
+ funcdata);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_h handle,
+ data_h rawdata,
+ nfc_transceive_data_callback callback,
+ void *user_data)
+{
+ net_nfc_target_info_s *target_info = NULL;
+ data_s *data = (data_s *)rawdata;
+
+ GVariant *arg_data = NULL;
+ TransceiveFuncData *funcdata = NULL;
+
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get TransceiveProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+
+ if (handle == NULL || rawdata == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ /* fill trans information struct */
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = transceive_data_to_transceive_variant(target_info->devType,
+ data);
+ if (arg_data == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ funcdata = g_new0(TransceiveFuncData, 1);
+
+ funcdata->transceive_send_callback = (gpointer)callback;
+ funcdata->transceive_send_data = user_data;
+
+ net_nfc_gdbus_transceive_call_transceive_data(transceive_proxy,
+ GPOINTER_TO_UINT(handle),
+ target_info->devType,
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ transceive_data_call,
+ funcdata);
+
+ return NET_NFC_OK;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_h handle,
+ data_h rawdata)
+{
+ net_nfc_target_info_s *target_info = NULL;
+ data_s *data = (data_s *)rawdata;
+
+ GError *error = NULL;
+ GVariant *arg_data = NULL;
+
+ net_nfc_error_e out_result;
+
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get TransceiveProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+
+ if (handle == NULL || rawdata == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ /* fill trans information struct */
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = transceive_data_to_transceive_variant(target_info->devType,
+ data);
+ if (arg_data == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ if(net_nfc_gdbus_transceive_call_transceive_sync(transceive_proxy,
+ GPOINTER_TO_UINT(handle),
+ target_info->devType,
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Transceive (sync call) failed: %s",
+ error->message);
+
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return out_result;
+}
+
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_transceive_data_sync(
+ net_nfc_target_handle_h handle,
+ data_h rawdata,
+ data_h *response)
+{
+ net_nfc_target_info_s *target_info = NULL;
+ data_s *data = (data_s *)rawdata;
+
+ GError *error = NULL;
+ GVariant *arg_data = NULL;
+ GVariant *out_data = NULL;
+
+ net_nfc_error_e out_result = NET_NFC_OK;
+
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get TransceiveProxy");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ DEBUG_CLIENT_MSG("send reqeust :: transceive = [%p]", handle);
+
+ if (handle == NULL || rawdata == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_client_tag_is_connected() == FALSE)
+ return NET_NFC_OPERATION_FAIL;
+
+ /* fill trans information struct */
+ target_info = net_nfc_client_tag_get_client_target_info();
+
+ if (target_info == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ arg_data = transceive_data_to_transceive_variant(target_info->devType,
+ data);
+ if (arg_data == NULL)
+ return NET_NFC_OPERATION_FAIL;
+
+ if (net_nfc_gdbus_transceive_call_transceive_data_sync(
+ transceive_proxy,
+ GPOINTER_TO_UINT(handle),
+ target_info->devType,
+ arg_data,
+ net_nfc_client_gdbus_get_privilege(),
+ (gint *)&out_result,
+ &out_data,
+ NULL,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Transceive (sync call) failed: %s",
+ error->message);
+ g_error_free(error);
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ if (response && out_data != NULL)
+ {
+ *response = net_nfc_util_gdbus_variant_to_data(out_data);
+ }
+
+ return out_result;
+}
+
+
+net_nfc_error_e net_nfc_client_transceive_init(void)
+{
+ GError *error = NULL;
+
+ if (transceive_proxy)
+ {
+ DEBUG_CLIENT_MSG("Already initialized");
+
+ return NET_NFC_OK;
+ }
+
+ transceive_proxy = net_nfc_gdbus_transceive_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.tizen.NetNfcService",
+ "/org/tizen/NetNfcService/Transceive",
+ NULL,
+ &error);
+ if (transceive_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
+ g_error_free(error);
+
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ return NET_NFC_OK;
+}
+
+void net_nfc_client_transceive_deinit(void)
+{
+ if(transceive_proxy)
+ {
+ g_object_unref(transceive_proxy);
+ transceive_proxy = NULL;
+ }
+}
#include <stdlib.h>
#include <string.h>
-#include "net_nfc_client_util_private.h"
+#include "net_nfc_client_util_internal.h"
prefix=/usr
exec_prefix=${prefix}/bin
libdir=@LIB_INSTALL_DIR@
-includedir=${prefix}/include
+includedir=${prefix}/include
Name: nfc
Description: NFC
Version: $version
-Requires:
+Requires:
Libs: -lnfc
-Cflags: -I/usr/include/nfc
+Cflags: -I/usr/include/nfc
\ No newline at end of file
SET(VERSION_MAJOR 1)
SET(VERSION ${VERSION_MAJOR}.0.0)
+FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
+EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
+ " \\
+ --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/net_nfc_gdbus \\
+ --c-namespace NetNfcGDbus\\
+ --interface-prefix org.tizen.NetNfcService. \\
+ ${CMAKE_CURRENT_SOURCE_DIR}/net_nfc.xml \\
+ ")
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} COMMON_LIB_SRCS)
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
INCLUDE(FindPkgConfig)
-pkg_check_modules(commonlib_pkges REQUIRED glib-2.0 dlog bluetooth-api libssl capi-appfw-app-manager)
+pkg_check_modules(commonlib_pkges REQUIRED
+ glib-2.0 gio-2.0 gio-unix-2.0 dlog bluetooth-api libssl)
FOREACH(flag ${commonlib_pkges_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDIF()
ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-#ADD_DEFINITIONS("-DSLP_DEBUG")
-ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE")
-#ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN")
-ADD_DEFINITIONS("-DSECURITY_SERVER")
ADD_LIBRARY(${NFC_COMMON_LIB} SHARED ${COMMON_LIB_SRCS})
SET_TARGET_PROPERTIES(${NFC_COMMON_LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET(COMMON_LIB_HEADER
include/net_nfc_typedef.h
- include/net_nfc_util_private.h
+ include/net_nfc_util_internal.h
include/net_nfc_oem_controller.h
- include/net_nfc_typedef_private.h
+ include/net_nfc_typedef_internal.h
include/net_nfc_util_ndef_message.h
include/net_nfc_util_handover.h
include/net_nfc_util_ndef_record.h
)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-INSTALL(TARGETS ${NFC_COMMON_LIB} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${NFC_COMMON_LIB}.pc DESTINATION lib/pkgconfig)
+INSTALL(TARGETS ${NFC_COMMON_LIB} DESTINATION lib)
FOREACH(hfile ${COMMON_LIB_HEADER})
INSTALL(FILES ${hfile} DESTINATION include/nfc-common-lib)
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#ifndef __NET_NFC_DEBUG_PRIVATE_H__
-#define __NET_NFC_DEBUG_PRIVATE_H__
+#ifndef __NET_NFC_DEBUG_INTERNAL_H__
+#define __NET_NFC_DEBUG_INTERNAL_H__
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <libgen.h>
+#include <dlog.h>
-// below define should define before dlog.h
#define LOG_SERVER_TAG "NET_NFC_MANAGER"
#define LOG_CLIENT_TAG "NET_NFC_CLIENT"
-#include <dlog.h>
-
#define LOG_COLOR_RED "\033[0;31m"
#define LOG_COLOR_GREEN "\033[0;32m"
#define LOG_COLOR_BROWN "\033[0;33m"
/* nfc_log_to_file */
extern FILE *nfc_log_file;
-#define NFC_DLOG_FILE "/opt/etc/nfc_debug/nfc_mgr_dlog.txt"
+#define NFC_DLOG_FILE "/opt/usr/share/nfc_debug/nfc_mgr_dlog.txt"
/* tag */
const char *net_nfc_get_log_tag();
-#define NFC_LOGD(format, arg...) (LOG_ON() ? (LOG(LOG_DEBUG, net_nfc_get_log_tag(), "%s:%s(%d)>" format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#define NFC_LOGE(format, arg...) (LOG_ON() ? (LOG(LOG_ERROR, net_nfc_get_log_tag(), "%s:%s(%d)>" format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#define NFC_LOGI(format, arg...) (LOG_ON() ? (LOG(LOG_INFO, net_nfc_get_log_tag(), "%s:%s(%d)>" format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
+#define NFC_LOGD(format, arg...) SLOG(LOG_DEBUG, net_nfc_get_log_tag(), format, ##arg)
+#define NFC_LOGI(format, arg...) SLOG(LOG_INFO, net_nfc_get_log_tag(), format, ##arg)
+#define NFC_LOGW(format, arg...) SLOG(LOG_WARN, net_nfc_get_log_tag(), format, ##arg)
+#define NFC_LOGE(format, arg...) SLOG(LOG_ERROR, net_nfc_get_log_tag(), format, ##arg)
+
+#ifndef SECURE_LOGD
+#define SECURE_LOGD NFC_LOGD
+#endif
#define DEBUG_MSG_PRINT_BUFFER(buffer, length) \
do { \
int i = 0, offset = 0; \
char temp_buffer[4096] = { 0, }; \
- NFC_LOGD(LOG_COLOR_BLUE " BUFFER [%d] = {" LOG_COLOR_END, length); \
+ NFC_LOGD(LOG_COLOR_BLUE "BUFFER [%d] = {" LOG_COLOR_END, length); \
for(; i < length && offset < sizeof(temp_buffer); i++) \
{ \
offset += snprintf(temp_buffer + offset, sizeof(temp_buffer) - offset, " %02x", buffer[i]); \
do { \
int i = 0, offset = 0; \
char temp_buffer[4096] = { 0, }; \
- NFC_LOGD(LOG_COLOR_BLUE " BUFFER [%d] = {" LOG_COLOR_END, length); \
+ NFC_LOGD(LOG_COLOR_BLUE "BUFFER [%d] = {" LOG_COLOR_END, length); \
for(; i < length && offset < sizeof(temp_buffer); i++) \
{ \
offset += snprintf(temp_buffer + offset, sizeof(temp_buffer) - offset, " %c", buffer[i]); \
#define DEBUG_MSG(format, args...) \
do { \
- NFC_LOGD(LOG_COLOR_BROWN " " format "" LOG_COLOR_END, ##args); \
+ NFC_LOGD(format, ##args); \
if (nfc_log_file) \
{ \
char timeBuf[50]; \
#define DEBUG_SERVER_MSG(format, args...) \
do {\
- NFC_LOGD(LOG_COLOR_PURPLE " " format "" LOG_COLOR_END, ##args);\
+ NFC_LOGD(LOG_COLOR_PURPLE format LOG_COLOR_END, ##args);\
if (nfc_log_file) \
{ \
char timeBuf[50]; \
#define DEBUG_CLIENT_MSG(format, args...) \
do {\
- NFC_LOGD(LOG_COLOR_GREEN " " format "" LOG_COLOR_END, ##args); \
+ NFC_LOGD(LOG_COLOR_CYAN format LOG_COLOR_END, ##args); \
if (nfc_log_file) \
{ \
char timeBuf[50]; \
#define DEBUG_ERR_MSG(format, args...) \
do {\
- NFC_LOGD(LOG_COLOR_RED " " format "" LOG_COLOR_END, ##args);\
+ NFC_LOGD(LOG_COLOR_RED format LOG_COLOR_END, ##args);\
if (nfc_log_file) \
{ \
char timeBuf[50]; \
time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
fprintf(nfc_log_file, "\n%s",timeBuf); \
- fprintf(nfc_log_file, "[ERR][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fprintf(nfc_log_file, "[E][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fflush(nfc_log_file);\
+ } \
+ } while(0)
+
+#define INFO_MSG(format, args...) \
+ do {\
+ NFC_LOGI(LOG_COLOR_GREEN format LOG_COLOR_END, ##args);\
+ if (nfc_log_file) \
+ { \
+ char timeBuf[50]; \
+ time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
+ fprintf(nfc_log_file, "\n%s",timeBuf); \
+ fprintf(nfc_log_file, "[I][%s:%d] "format"",__func__, __LINE__, ##args); \
+ fflush(nfc_log_file);\
+ } \
+ } while(0)
+
+#define WARN_MSG(format, args...) \
+ do {\
+ NFC_LOGW(LOG_COLOR_BROWN format LOG_COLOR_END, ##args);\
+ if (nfc_log_file) \
+ { \
+ char timeBuf[50]; \
+ time_t rawtime; time (&rawtime); strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", localtime(&rawtime)); \
+ fprintf(nfc_log_file, "\n%s",timeBuf); \
+ fprintf(nfc_log_file, "[W][%s:%d] "format"",__func__, __LINE__, ##args); \
fflush(nfc_log_file);\
} \
} while(0)
NFC_LOGD("\t time = [%s]", time_string);\
} while(0)
-#endif
+#endif //__NET_NFC_DEBUG_INTERNAL_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_OEM_CONTROLLER_H__
+#define __NET_NFC_OEM_CONTROLLER_H__
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_OEM_CONTROLLER_H
-#define NET_NFC_OEM_CONTROLLER_H
-
-#include "net_nfc_typedef_private.h"
+#include "net_nfc_typedef_internal.h"
typedef bool (*net_nfc_oem_controller_init)(net_nfc_error_e *result);
typedef bool (*net_nfc_oem_controller_deinit)(void);
typedef bool (*net_nfc_oem_controller_llcp_create_socket)(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, void *user_param);
typedef bool (*net_nfc_oem_controller_llcp_bind)(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result);
typedef bool (*net_nfc_oem_controller_llcp_listen)(net_nfc_target_handle_s *handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
-typedef bool (*net_nfc_oem_controller_llcp_accept)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
+typedef bool (*net_nfc_oem_controller_llcp_accept)(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
typedef bool (*net_nfc_oem_controller_llcp_connect_by_url)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, void *user_param);
typedef bool (*net_nfc_oem_controller_llcp_connect)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, void *user_param);
typedef bool (*net_nfc_oem_controller_llcp_disconnect)(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
net_nfc_oem_controller_secure_element_close secure_element_close;
} net_nfc_oem_interface_s;
-#endif
+#endif //__NET_NFC_OEM_CONTROLLER_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TYPEDEF_H__
+#define __NET_NFC_TYPEDEF_H__
/**
NFC Manager
*/
-#ifndef __NET_NFC_TYPEDEF_H__
-#define __NET_NFC_TYPEDEF_H__
-
/**
@defgroup NET_NFC_MANAGER The description of NFC Manager
@defgroup NET_NFC_TYPEDEF Defines and structures
NET_NFC_MESSAGE_TAG_DETACHED, /**< Type: Notify Event, <br> When a tag or SE is disappeared, you got this event.
<br> The data contains the target info , need to cast to net_nfc_target_info_h but it does not have detail target info
<br> please, do not use "net_nfc_get_tag_info_keys" when you got this event*/
- NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event <br> After complete "net_nfc_format_ndef", this event is delivered */
+/*10*/ NET_NFC_MESSAGE_FORMAT_NDEF, /**< Type: Response Event <br> After complete "net_nfc_format_ndef", this event is delivered */
NET_NFC_MESSAGE_LLCP_DISCOVERED,/**< Type: Notify Event <br> When LLCP is discovered and remote device is support llcp, you receive this event
<br> data pointer contains the remote llcp configuration info. Cast to net_nfc_llcp_config_info_h*/
NET_NFC_MESSAGE_P2P_DETACHED, /**< Type: Notify Event <br> When LLCP is de-activated by removing the device, you receive this event*/
NET_NFC_MESSAGE_SE_START_TRANSACTION, /**< Type: Notify Event, indicates external reader start transaction*/
NET_NFC_MESSAGE_SE_END_TRANSACTION, /**< Type: Notify Event, indicates external reader end transaction*/
NET_NFC_MESSAGE_SE_TYPE_TRANSACTION, /**< Type: Notify Event, Indicates external reader trying to access secure element */
- NET_NFC_MESSAGE_SE_CONNECTIVITY, /**< Type: Notify Event, This event notifies the terminal host that it shall send a connectivity event from UICC */
+/*20*/ NET_NFC_MESSAGE_SE_CONNECTIVITY, /**< Type: Notify Event, This event notifies the terminal host that it shall send a connectivity event from UICC */
NET_NFC_MESSAGE_SE_FIELD_ON, /**< Type: Notify Event, indicates external reader field is on*/
NET_NFC_MESSAGE_SE_FIELD_OFF, /**< Type: Notify Event, indicates external reader field is off*/
NET_NFC_MESSAGE_SE_TYPE_CHANGED, /**< Type: Notify Event, indicates secure element type is changed*/
NET_NFC_MESSAGE_OPEN_INTERNAL_SE,
NET_NFC_MESSAGE_CLOSE_INTERNAL_SE,
NET_NFC_MESSAGE_SEND_APDU_SE,
- NET_NFC_MESSAGE_GET_ATR_SE,
+/*30*/ NET_NFC_MESSAGE_GET_ATR_SE,
NET_NFC_GET_SERVER_STATE,
NET_NFC_MESSAGE_SIM_TEST,
- NET_NFC_MESSAGE_INIT,/*31*/
+ NET_NFC_MESSAGE_INIT,
NET_NFC_MESSAGE_DEINIT,
NET_NFC_MESSAGE_PRBS_TEST,
NET_NFC_MESSAGE_GET_FIRMWARE_VERSION,
NET_NFC_MESSAGE_SET_EEDATA,
+
+ NET_NFC_MESSAGE_SNEP_START_SERVER,
+ NET_NFC_MESSAGE_SNEP_START_CLIENT,
+/*40*/ NET_NFC_MESSAGE_SNEP_REQUEST,
+ NET_NFC_MESSAGE_SNEP_STOP_SERVICE,
+ NET_NFC_MESSAGE_SNEP_REGISTER_SERVER,
+ NET_NFC_MESSAGE_SNEP_UNREGISTER_SERVER,
+
+ NET_NFC_MESSAGE_CONNECT,
+ NET_NFC_MESSAGE_DISCONNECT,
+ NET_NFC_MESSAGE_SET_CARD_EMULATION,
} net_nfc_message_e;
typedef enum
<br> data pointer contains received data (Cast to data_h)*/
NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, /**< Type: Response Event,<br> "net_nfc_receive_llcp_from" operation is completed (connectionless mode)*/
NET_NFC_MESSAGE_LLCP_DISCONNECT, /**< Type: Response Event,<br> "net_nfc_disconnect_llcp" request is completed */
- NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,<br> when the socket is disconnected or rejected, you may receive this event */
+ NET_NFC_MESSAGE_LLCP_ERROR, /**< Type: Notify Event,<br> when the socket is disconnected, you may receive this event */
+ NET_NFC_MESSAGE_LLCP_CONNECT_REQ, /**< Type: Notify Event,<br> when the peer requests connect, you may receive this event */
+ NET_NFC_MESSAGE_LLCP_ACCEPT, /**< Type: Response Event <br> this event indicates "net_nfc_accept_llcp" requested is completed*/
+ NET_NFC_MESSAGE_LLCP_REJECT, /**< Type: Response Event <br> this event indicates "net_nfc_reject_llcp" requested is completed*/
+ NET_NFC_MESSAGE_LLCP_REJECTED, /**< Type: Notify Event,<br> when the socket is rejected, you may receive this event */
+ NET_NFC_MESSAGE_LLCP_CLOSE, /**< Type: Response Event,<br> "net_nfc_close_llcp_socket" request is completed */
} net_nfc_llcp_message_e;
typedef uint32_t net_nfc_llcp_socket_t;
+typedef void *net_nfc_snep_handle_h;
+
// LLCP Callback
typedef void (*net_nfc_llcp_socket_cb)(net_nfc_llcp_message_e message, net_nfc_error_e result, void *data, void *user_data, void *trans_data);
NET_NFC_MAX_CERT_FORMAT,
} net_nfc_cert_format_t;
+typedef enum
+{
+ NET_NFC_SNEP_GET = 1,
+ NET_NFC_SNEP_PUT = 2,
+} net_nfc_snep_type_t;
+
+typedef enum
+{
+ NET_NFC_LLCP_REGISTERED = -1,
+ NET_NFC_LLCP_UNREGISTERED = -2,
+ NET_NFC_LLCP_START = -3,
+ NET_NFC_LLCP_STOP = -4,
+}
+net_nfc_llcp_state_t;
+
+typedef enum
+{
+ NET_NFC_CARD_EMELATION_ENABLE = 0,
+ NET_NFC_CARD_EMULATION_DISABLE,
+}
+net_nfc_card_emulation_mode_t;
+
#ifdef __cplusplus
}
#endif
@}
*/
-#endif
-
+#endif //__NET_NFC_TYPEDEF_H__
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#ifndef __NET_NFC_INTERNAL_TYPEDEF_H__
-#define __NET_NFC_INTERNAL_TYPEDEF_H__
+#ifndef __NET_NFC_TYPEDEF_INTERNAL_H__
+#define __NET_NFC_TYPEDEF_INTERNAL_H__
#include "net_nfc_typedef.h"
{
data_s aid;
data_s param;
-}net_nfc_se_event_info_s;
+} net_nfc_se_event_info_s;
typedef struct _net_nfc_transceive_info_s
{
}
net_nfc_connection_handover_info_s;
-#ifdef BROADCAST_MESSAGE
-typedef struct _net_nfc_server_received_message_s
-{
- int mes_type;
- int client_fd;
- struct _net_nfc_server_received_message_s *next;
-}net_nfc_server_received_message_s;
-#endif
-
typedef enum _client_state_e
{
NET_NFC_CLIENT_INACTIVE_STATE = 0x00,
NET_NFC_CLIENT_ACTIVE_STATE,
} client_state_e;
+typedef enum _net_nfc_launch_popup_check_e
+{
+ CHECK_FOREGROUND = 0x00,
+ NO_CHECK_FOREGROUND,
+} net_nfc_launch_popup_check_e;
+
typedef enum _net_nfc_launch_popup_state_e
{
NET_NFC_LAUNCH_APP_SELECT = 0x00,
} net_nfc_launch_popup_state_e;
/* server state */
-#define NET_NFC_SERVER_IDLE 0
-#define NET_NFC_SERVER_DISCOVERY (1 << 1)
-#define NET_NFC_TAG_CONNECTED (1 << 2)
-#define NET_NFC_SE_CONNECTED (1 << 3)
+#define NET_NFC_SERVER_IDLE 0
+#define NET_NFC_SERVER_DISCOVERY (1 << 1)
+#define NET_NFC_TAG_CONNECTED (1 << 2)
+#define NET_NFC_SE_CONNECTED (1 << 3)
#define NET_NFC_SNEP_CLIENT_CONNECTED (1 << 4)
-#define NET_NFC_NPP_CLIENT_CONNECTED (1 << 5)
+#define NET_NFC_NPP_CLIENT_CONNECTED (1 << 5)
#define NET_NFC_SNEP_SERVER_CONNECTED (1 << 6)
-#define NET_NFC_NPP_SERVER_CONNECTED (1 << 7)
+#define NET_NFC_NPP_SERVER_CONNECTED (1 << 7)
// these are messages for request
#define NET_NFC_REQUEST_MSG_HEADER \
NET_NFC_REQUEST_MSG_HEADER
} net_nfc_request_msg_t;
-typedef struct _net_nfc_request_change_client_state_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- client_state_e client_state;
-} net_nfc_request_change_client_state_t;
-
-typedef struct _net_nfc_request_set_launch_state_t
-{
- NET_NFC_REQUEST_MSG_HEADER
- net_nfc_launch_popup_state_e set_launch_popup;
-}net_nfc_request_set_launch_state_t;
-
-typedef struct _net_nfc_request_transceive_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
- struct
- {
- uint32_t dev_type;
- net_nfc_data_s trans_data;
- } info;
-} net_nfc_request_transceive_t;
-
-typedef struct _net_nfc_request_target_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
- uint32_t uint_param;
- net_nfc_data_s data;
-} net_nfc_request_target_t;
-
-typedef struct _net_nfc_request_read_ndef_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
-} net_nfc_request_read_ndef_t;
-
-typedef struct _net_nfc_request_test_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
- uint32_t tech;
- uint32_t rate;
-} net_nfc_request_test_t;
-
-typedef struct _net_nfc_eedata_register_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
- uint32_t mode;
- uint32_t reg_id;
- net_nfc_data_s data;
-} net_nfc_request_eedata_register_t;
-
-typedef struct _net_nfc_request_make_read_only_ndef_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
-} net_nfc_request_make_read_only_ndef_t;
-
-typedef struct _net_nfc_request_is_tag_connected_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- void *trans_param;
-} net_nfc_request_is_tag_connected_t;
-
-typedef struct _net_nfc_request_write_ndef_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
- net_nfc_data_s data;
-} net_nfc_request_write_ndef_t;
-
-typedef struct _net_nfc_request_format_ndef_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
- net_nfc_data_s key;
-} net_nfc_request_format_ndef_t;
-
-typedef struct _net_nfc_request_terminate_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- void *object;
-} net_nfc_request_terminate_t;
-
-
-typedef struct _net_nfc_request_reset_mode_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- int mode;
-} net_nfc_request_reset_mode_t;
-
typedef struct _net_nfc_request_target_detected_t
{
NET_NFC_REQUEST_MSG_HEADER
data_s aid;
data_s param;
-}net_nfc_request_se_event_t;
-
-typedef struct _net_nfc_request_get_current_tag_info_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- void *trans_param;
-} net_nfc_request_get_current_tag_info_t;
-
-typedef struct _net_nfc_request_get_current_target_handle_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- void *trans_param;
-} net_nfc_request_get_current_target_handle_t;
+} net_nfc_request_se_event_t;
typedef struct _net_nfc_request_llcp_msg_t
{
NET_NFC_REQUEST_MSG_HEADER
uint32_t result;
-} net_nfc_request_llcp_msg_t;
-
-typedef struct _net_nfc_request_p2p_send_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_exchanger_data_type_e data_type;
- net_nfc_data_s data;
-} net_nfc_request_p2p_send_t;
-
-typedef struct _net_nfc_request_accept_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t incomming_socket;
- void *trans_param;
-} net_nfc_request_accept_socket_t;
-
-typedef struct _net_nfc_request_terminate_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
net_nfc_llcp_socket_t llcp_socket;
-} net_nfc_request_terminate_socket_t;
+} net_nfc_request_llcp_msg_t;
typedef struct _net_nfc_request_listen_socket_t
{
net_nfc_data_s service_name;
} net_nfc_request_listen_socket_t;
-typedef struct _net_nfc_request_reject_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t incomming_socket;
- void *trans_param;
-} net_nfc_request_reject_socket_t;
-
-typedef struct _net_nfc_request_connect_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- uint16_t miu; /** The remote Maximum Information Unit */
- uint8_t rw; /** The Receive Window size (4 bits)*/
- net_nfc_socket_type_e type;
- void *trans_param;
- net_nfc_data_s service_name;
-} net_nfc_request_connect_socket_t;
-
-typedef struct _net_nfc_request_connect_sap_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- uint16_t miu; /** The remote Maximum Information Unit */
- uint8_t rw; /** The Receive Window size (4 bits)*/
- net_nfc_socket_type_e type;
- sap_t sap;
- void *trans_param;
-} net_nfc_request_connect_sap_socket_t;
-
-typedef struct _net_nfc_request_disconnect_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- void *trans_param;
-} net_nfc_request_disconnect_socket_t;
-
-typedef struct _net_nfc_request_send_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- void *trans_param;
- net_nfc_data_s data;
-} net_nfc_request_send_socket_t;
-
typedef struct _net_nfc_request_receive_socket_t
{
NET_NFC_REQUEST_MSG_HEADER
net_nfc_llcp_socket_t oal_socket;
size_t req_length;
void *trans_param;
-} net_nfc_request_receive_socket_t;
-
-typedef struct _net_nfc_request_send_to_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- void *trans_param;
net_nfc_data_s data;
-} net_nfc_request_send_to_socket_t;
+} net_nfc_request_receive_socket_t;
typedef struct _net_nfc_request_receive_from_socket_t
{
net_nfc_llcp_socket_t client_socket;
net_nfc_llcp_socket_t oal_socket;
size_t req_length;
- void *trans_param;
-} net_nfc_request_receive_from_socket_t;
-
-typedef struct _net_nfc_request_close_socket_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- void *trans_param;
-} net_nfc_request_close_socket_t;
-
-typedef struct _net_nfc_request_config_llcp_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_config_info_s config;
- void *trans_param;
-} net_nfc_request_config_llcp_t;
-
-typedef struct _net_nfc_response_llcp_socket_error_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t oal_socket;
- net_nfc_llcp_socket_t client_socket;
- net_nfc_error_e error;
- void *trans_param;
-} net_nfc_response_llcp_socket_error_t;
-
-typedef struct _net_nfc_request_watch_dog_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t devType;
- net_nfc_target_handle_s *handle;
-} net_nfc_request_watch_dog_t;
-
-typedef struct _net_nfc_request_set_se_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint8_t se_type;
- void *trans_param;
-} net_nfc_request_set_se_t;
-
-typedef struct _net_nfc_request_get_se_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- void *trans_param;
-} net_nfc_request_get_se_t;
-
-typedef struct _net_nfc_request_open_internal_se_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint8_t se_type;
- void *trans_param;
-} net_nfc_request_open_internal_se_t;
-
-typedef struct _net_nfc_request_close_internal_se_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
-} net_nfc_request_close_internal_se_t;
-
-typedef struct _net_nfc_request_send_apdu_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
+ sap_t sap;
void *trans_param;
net_nfc_data_s data;
-} net_nfc_request_send_apdu_t;
-
-typedef struct _net_nfc_request_get_atr_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
-} net_nfc_request_get_atr_t;
-
-typedef struct _net_nfc_request_connection_handover_t
-{
- NET_NFC_REQUEST_MSG_HEADER
-
- uint32_t result;
- net_nfc_target_handle_s *handle;
- net_nfc_conn_handover_carrier_type_e type;
-}
-net_nfc_request_connection_handover_t;
-
-// these are messages for response
-//
-
-#define NET_NFC_RESPONSE_MSG_HEADER \
- /* DON'T MODIFY THIS CODE - BEGIN */ \
- uint32_t length; \
- uint32_t response_type; \
- uint32_t flags; \
- uint32_t user_param; \
- net_nfc_error_e result;
- /* DON'T MODIFY THIS CODE - END */
-
-typedef struct _net_nfc_response_msg_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-// int response_type; /* NET_NFC_MESSAGE : this type should be int DON'T USE enum! Because two enum values are used net_nfc_llcp_message_e and net_nfc_message_e enum */
- void *detail_message;
-} net_nfc_response_msg_t;
-
-typedef struct _net_nfc_response_test_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
-} net_nfc_response_test_t;
-
-typedef struct _net_nfc_response_notify_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
-} net_nfc_response_notify_t;
-
-typedef struct _net_nfc_response_init_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
-} net_nfc_response_init_t;
-
-typedef struct _net_nfc_response_tag_discovered_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- uint32_t devType;
- uint8_t is_ndef_supported;
- uint8_t ndefCardState;
- uint32_t maxDataSize;
- uint32_t actualDataSize;
- int number_of_keys;
- data_s target_info_values;
- data_s raw_data;
-} net_nfc_response_tag_discovered_t;
-
-typedef struct _net_nfc_response_se_event_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- data_s aid;
- data_s param;
-} net_nfc_response_se_event_t;
-
-typedef struct _net_nfc_response_get_current_tag_info_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- uint32_t devType;
- uint8_t is_ndef_supported;
- uint8_t ndefCardState;
- uint32_t maxDataSize;
- uint32_t actualDataSize;
- int number_of_keys;
- data_s target_info_values;
- data_s raw_data;
- void *trans_param;
-} net_nfc_response_get_current_tag_info_t;
-
-typedef struct _net_nfc_response_get_current_target_handle_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- uint32_t devType;
- void *trans_param;
-} net_nfc_response_get_current_target_handle_t;
-
-typedef struct _net_nfc_response_target_detached_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- uint32_t devType;
-} net_nfc_response_target_detached_t;
-
-typedef struct _net_nfc_response_transceive_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
- data_s data;
-} net_nfc_response_transceive_t;
-
-typedef struct _net_nfc_response_read_ndef_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
- data_s data;
-} net_nfc_response_read_ndef_t;
-
-typedef struct _net_nfc_response_write_ndef_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
-} net_nfc_response_write_ndef_t;
-
-typedef struct _net_nfc_response_make_read_only_ndef_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
-} net_nfc_response_make_read_only_ndef_t;
-
-typedef struct _net_nfc_response_is_tag_connected_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
- net_nfc_target_type_e devType;
-} net_nfc_response_is_tag_connected_t;
-
-typedef struct _net_nfc_response_format_ndef_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
-} net_nfc_response_format_ndef_t;
-
-typedef struct _net_nfc_response_p2p_discovered_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
-} net_nfc_response_p2p_discovered_t;
-
-typedef struct _net_nfc_response_p2p_send_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- void *trans_param;
-} net_nfc_response_p2p_send_t;
-
-typedef struct _net_nfc_response_llcp_discovered_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- uint32_t devType;
- int number_of_keys;
- data_s target_info_values;
- net_nfc_llcp_config_info_s llcp_config_info;
-} net_nfc_response_llcp_discovered_t;
-
-typedef struct _net_nfc_response_llcp_detached_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
-} net_nfc_response_llcp_detached_t;
-
-typedef struct _net_nfc_response_incomming_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t oal_socket;
- net_nfc_llcp_socket_option_s option;
- net_nfc_target_handle_s *handle;
- net_nfc_llcp_socket_t incomming_socket;
-} net_nfc_response_incomming_llcp_t;
-
-typedef struct _net_nfc_response_listen_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- void *trans_param;
-} net_nfc_response_listen_socket_t;
-
-typedef struct _net_nfc_response_connect_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- void *trans_param;
-} net_nfc_response_connect_socket_t;
-
-typedef struct _net_nfc_response_connect_sap_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- net_nfc_llcp_socket_t oal_socket;
- void *trans_param;
-} net_nfc_response_connect_sap_socket_t;
-
-typedef struct _net_nfc_response_accept_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- void *trans_param;
-} net_nfc_response_accept_socket_t;
-
-typedef struct _net_nfc_response_reject_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- void *trans_param;
-} net_nfc_response_reject_socket_t;
-
-typedef struct _net_nfc_response_send_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- void *trans_param;
-} net_nfc_response_send_socket_t;
-
-typedef struct _net_nfc_response_receive_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- data_s data;
- void *trans_param;
-} net_nfc_response_receive_socket_t;
-
-typedef struct _net_nfc_response_p2p_receive_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- data_s data;
-} net_nfc_response_p2p_receive_t;
-
-typedef struct _net_nfc_response_config_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
-} net_nfc_response_config_llcp_t;
-
-typedef struct _net_nfc_response_close_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- void *trans_param;
-} net_nfc_response_close_socket_t;
-
-typedef struct _net_nfc_response_disconnect_llcp_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_llcp_socket_t client_socket;
- void *trans_param;
-} net_nfc_response_disconnect_socket_t;
-
-typedef struct _net_nfc_response_set_se_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- uint8_t se_type;
- void *trans_param;
-} net_nfc_response_set_se_t;
-
-typedef struct _net_nfc_response_get_se_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- uint8_t se_type;
- void *trans_param;
-} net_nfc_response_get_se_t;
-
-typedef struct _net_nfc_response_open_internal_se_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_target_handle_s *handle;
- uint8_t se_type;
- void* trans_param;
-} net_nfc_response_open_internal_se_t;
-
-typedef struct _net_nfc_response_close_internal_se_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- void *trans_param;
-} net_nfc_response_close_internal_se_t;
-
-typedef struct _net_nfc_response_send_apdu_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- data_s data;
- void *trans_param;
-} net_nfc_response_send_apdu_t;
-
-typedef struct _net_nfc_response_get_atr_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- data_s data;
-} net_nfc_response_get_atr_t;
-
-typedef struct _net_nfc_response_get_server_state_t
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- uint32_t state;
-} net_nfc_response_get_server_state_t;
-
-typedef struct _net_nfc_response_connection_handover
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- net_nfc_exchanger_event_e event;
- net_nfc_conn_handover_carrier_type_e type;
- data_s data;
-}
-net_nfc_response_connection_handover_t;
-
-typedef struct _net_nfc_response_get_firmware_version
-{
- NET_NFC_RESPONSE_MSG_HEADER
-
- data_s data;
-}
-net_nfc_response_firmware_version_t;
-
-typedef struct _client_context
-{
- void *register_user_param; /* parameter that registed in the cb register time */
- net_nfc_error_e result;
- pthread_mutex_t g_client_lock;
- net_nfc_event_filter_e filter;
-#ifdef SAVE_TARGET_INFO_IN_CC
- net_nfc_target_info_s *target_info;
-#endif
- bool initialized;
- int set_launch_popup;
-} client_context_t;
+} net_nfc_request_receive_from_socket_t;
// data exchanger
typedef struct _net_nfc_exchanger_data_s
{
NET_NFC_MESSAGE_SERVICE_RESET = 2000,
NET_NFC_MESSAGE_SERVICE_INIT,
+ NET_NFC_MESSAGE_SERVICE_ACTIVATE,
+ NET_NFC_MESSAGE_SERVICE_DEACTIVATE,
NET_NFC_MESSAGE_SERVICE_DEINIT,
NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED,
NET_NFC_MESSAGE_SERVICE_SE,
NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED,
NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED,
NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP,
+ NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN,
+ NET_NFC_MESSAGE_SERVICE_LLCP_INCOMING,
NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT,
+ NET_NFC_MESSAGE_SERVICE_LLCP_REJECT,
NET_NFC_MESSAGE_SERVICE_LLCP_SEND,
NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO,
NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE,
NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED,
NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR,
NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR,
- NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE, /**< Type: Response Event,<br> "net_nfc_close_llcp_socket" request is completed */
NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE,
NET_NFC_MESSAGE_SERVICE_WATCH_DOG,
NET_NFC_MESSAGE_SERVICE_CLEANER,
}
__attribute__((packed)) net_nfc_certificate_chain_s;
-#define SMART_POSTER_RECORD_TYPE "Sp"
-#define URI_RECORD_TYPE "U"
-#define TEXT_RECORD_TYPE "T"
-#define GC_RECORD_TYPE "Gc"
-#define SIGNATURE_RECORD_TYPE "Sig"
-#define CONN_HANDOVER_REQ_RECORD_TYPE "Hr"
-#define CONN_HANDOVER_SEL_RECORD_TYPE "Hs"
-#define CONN_HANDOVER_CAR_RECORD_TYPE "Hc"
-#define COLLISION_DETECT_RECORD_TYPE "cr"
-#define ALTERNATIVE_RECORD_TYPE "ac"
-#define ERROR_RECORD_TYPE "err"
+#define SMART_POSTER_RECORD_TYPE "Sp"
+#define URI_RECORD_TYPE "U"
+#define TEXT_RECORD_TYPE "T"
+#define GC_RECORD_TYPE "Gc"
+#define SIGNATURE_RECORD_TYPE "Sig"
+#define CH_REQ_RECORD_TYPE "Hr"
+#define CH_SEL_RECORD_TYPE "Hs"
+#define CH_CAR_RECORD_TYPE "Hc"
+#define COLLISION_DETECT_RECORD_TYPE "cr"
+#define ALTERNATIVE_RECORD_TYPE "ac"
+#define ERROR_RECORD_TYPE "err"
#define URI_SCHEM_FILE "file://"
-#define UICC_TARGET_HANDLE 0xFF
+typedef void (*net_nfc_service_llcp_cb)(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, data_s *data, void *extra, void *user_param);
+typedef struct _net_nfc_llcp_param_t
+{
+ net_nfc_llcp_socket_t socket;
+ net_nfc_service_llcp_cb cb;
+ data_s data;
+ void *user_param;
+}
+net_nfc_llcp_param_t;
-#endif
+#endif //__NET_NFC_TYPEDEF_INTERNAL_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_UTIL_DEFINES__
-#define __NET_NFC_UTIL_DEFINES__
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_DEFINES_H__
+#define __NET_NFC_UTIL_DEFINES_H__
#define NET_NFC_UTIL_MSG_TYPE_REQUEST 0
#define NET_NFC_UTIL_MSG_TYPE_RESPONSE 1
-#define CONN_HANOVER_MAJOR_VER 1
-#define CONN_HANOVER_MINOR_VER 2
-
#define CONN_HANDOVER_BT_CARRIER_MIME_NAME "application/vnd.bluetooth.ep.oob"
#define CONN_HANDOVER_WIFI_BSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc"
#define CONN_HANDOVER_WIFI_IBSS_CARRIER_MIME_NAME "application/vnd.wfa.wsc;mode=ibss"
#define BLUETOOTH_ADDRESS_LENGTH 6
#define HIDDEN_BT_ADDR_FILE "/opt/etc/.bd_addr"
-/* define vconf key */
-#define NET_NFC_DISABLE_LAUNCH_POPUP_KEY "memory/private/nfc-manager/popup_disabled"//"memory/nfc/popup_disabled"
-
-#endif
+#endif //__NET_NFC_UTIL_DEFINES_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_GDBUS_INTERNAL_H__
+#define __NET_NFC_UTIL_GDBUS_INTERNAL_H__
+
+#include <glib.h>
+
+#include "net_nfc_typedef_internal.h"
+
+void net_nfc_util_gdbus_variant_to_buffer(GVariant *variant, uint8_t **buffer,
+ size_t *length);
+
+data_s *net_nfc_util_gdbus_variant_to_data(GVariant *variant);
+
+void net_nfc_util_gdbus_variant_to_data_s(GVariant *variant, data_s *data);
+
+GVariant *net_nfc_util_gdbus_buffer_to_variant(const uint8_t *buffer,
+ size_t length);
+
+GVariant *net_nfc_util_gdbus_data_to_variant(const data_s *data);
+
+#endif //__NET_NFC_UTIL_GDBUS_INTERNAL_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_UTIL_HANDOVER__
-#define __NET_NFC_UTIL_HANDOVER__
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_HANDOVER_H__
+#define __NET_NFC_UTIL_HANDOVER_H__
-#include "net_nfc_typedef_private.h"
+#include "net_nfc_typedef_internal.h"
#ifdef __cplusplus
extern "C"
{
#endif
+#define CH_MAJOR_VER 1
+#define CH_MINOR_VER 2
+#define CH_VERSION ((CH_MAJOR_VER << 4) | CH_MINOR_VER)
+
+#define CH_SAN "urn:nfc:sn:handover"
+#define CH_SAP 0x11 /* connection handover service access point */
+
net_nfc_error_e net_nfc_util_create_carrier_config(net_nfc_carrier_config_s **config, net_nfc_conn_handover_carrier_type_e type);
net_nfc_error_e net_nfc_util_add_carrier_config_property(net_nfc_carrier_config_s *config, uint16_t attribute, uint16_t size, uint8_t *data);
}
#endif
-#endif
+#endif //__NET_NFC_UTIL_HANDOVER_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_UTIL_H__
-#define __NET_NFC_UTIL_H__
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_INTERNAL_H__
+#define __NET_NFC_UTIL_INTERNAL_H__
#include <stdio.h>
#include <libgen.h>
#include <netinet/in.h>
-#include "net_nfc_typedef_private.h"
+#include "net_nfc_typedef_internal.h"
#define NET_NFC_REVERSE_ORDER_6_BYTES(__array) \
do \
uint16_t __x = htons(*(uint16_t *)(__array + 4)); \
*(uint32_t *)(__array + 2) = htonl(*(uint32_t *)(__array)); \
*(uint16_t *)(__array) = __x; \
- } while (0);
+ } while (0)
#define NET_NFC_REVERSE_ORDER_16_BYTES(array) \
do \
*(uint32_t *)(array + 12) = htonl(*(uint32_t *)(array)); \
*(uint32_t *)(array) = __x1; \
*(uint32_t *)(array + 4) = __x2; \
- } while (0);
-
+ } while (0)
typedef enum
{
bool net_nfc_util_duplicate_data(data_s *dest, net_nfc_data_s *src);
void net_nfc_util_free_data(data_s *data);
-void net_nfc_util_mem_free_detail_msg(int msg_type, int message, void *data);
-
net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type);
uint8_t *net_nfc_util_get_local_bt_address();
void net_nfc_util_compute_CRC(CRC_type_e CRC_type, uint8_t *buffer, uint32_t length);
const char *net_nfc_util_get_schema_string(int index);
-pid_t net_nfc_util_get_current_app_pgid(pid_t pid);
-#endif
+#endif //__NET_NFC_UTIL_INTERNAL_H__
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#ifndef NET_NFC_UTIL_IPC_H_
-#define NET_NFC_UTIL_IPC_H_
+#ifndef __NET_NFC_UTIL_IPC_H__
+#define __NET_NFC_UTIL_IPC_H__
#define NET_NFC_SERVER_ADDRESS "127.0.0.1"
#define NET_NFC_SERVER_PORT 3000
int net_nfc_util_fill_va_list(uint8_t *buffer, int length, va_list list);
void net_nfc_util_set_non_block_socket(int socket);
-#endif /* NET_NFC_UTIL_IPC_H_ */
+#endif //__NET_NFC_UTIL_IPC_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_UTIL_NDEF_MESSAGE__
-#define __NET_NFC_UTIL_NDEF_MESSAGE__
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_NDEF_MESSAGE_H__
+#define __NET_NFC_UTIL_NDEF_MESSAGE_H__
-#include "net_nfc_typedef_private.h"
+#include "net_nfc_typedef_internal.h"
/**
* \brief These are the flags specifying the content, structure or purpose of a NDEF Record.
net_nfc_error_e net_nfc_util_search_record_by_id(ndef_message_s *ndef_message, data_s *id, ndef_record_s **record);
-#endif
-
+#endif //__NET_NFC_UTIL_NDEF_MESSAGE_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __NET_NFC_UTIL_NDEF_RECORD__
-#define __NET_NFC_UTIL_NDEF_RECORD__
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_NDEF_RECORD_H__
+#define __NET_NFC_UTIL_NDEF_RECORD_H__
-#include "net_nfc_typedef_private.h"
+#include "net_nfc_typedef_internal.h"
/*
create record structure with basic info
*/
net_nfc_error_e net_nfc_util_create_uri_string_from_uri_record(ndef_record_s *record, char **uri);
-#endif
+#endif //__NET_NFC_UTIL_NDEF_RECORD_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_UTIL_OPENSSL_PRIVATE_H_
-#define NET_NFC_UTIL_OPENSSL_PRIVATE_H_
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_OPENSSL_INTERNAL_H__
+#define __NET_NFC_UTIL_OPENSSL_INTERNAL_H__
#include <openssl/x509.h>
bool net_nfc_util_openssl_decode_base64(const char *buffer, uint8_t *result, uint32_t *out_len, bool new_line_char);
bool net_nfc_util_openssl_digest(const char *algorithm, const uint8_t *buffer, const uint32_t buf_len, uint8_t *result, uint32_t *out_len);
-#endif /* NET_NFC_UTIL_OPENSSL_PRIVATE_H_ */
+#endif //__NET_NFC_UTIL_OPENSSL_INTERNAL_H__
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NET_NFC_UTIL_SIGN_RECORD_H
-#define __NET_NFC_UTIL_SIGN_RECORD_H
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_UTIL_SIGN_RECORD_H__
+#define __NET_NFC_UTIL_SIGN_RECORD_H__
-#include "net_nfc_typedef_private.h"
+#include "net_nfc_typedef_internal.h"
/*
* sign ndef record and ndef message
net_nfc_error_e net_nfc_util_verify_signature_records(ndef_record_s *begin_record, ndef_record_s *sign_record);
-#endif /* __NET_NFC_UTIL_SIGN_RECORD_H */
+#endif //__NET_NFC_UTIL_SIGN_RECORD_H__
--- /dev/null
+<!--
+ org.tizen.NfcService
+
+-->
+
+<node>
+ <interface name="org.tizen.NetNfcService.Manager">
+ <!--
+ SetActive
+ -->
+ <method name="SetActive">
+ <arg type="b" name="is_active" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ </method>
+
+ <!--
+ GetServerState
+ -->
+ <method name="GetServerState">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="state" direction="out" />
+ </method>
+
+
+ <!--
+ Activated
+ -->
+ <signal name="Activated">
+ <arg type="b" name="active" />
+ </signal>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Tag">
+ <!--
+ IsConnected
+ -->
+ <method name="IsTagConnected">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="b" name="is_connected" direction="out" />
+ <arg type="i" name="dev_type" direction="out" />
+ </method>
+
+ <!--
+ GetInfo
+ -->
+ <method name="GetCurrentTagInfo">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="b" name="is_connected" direction="out" />
+ <arg type="u" name="handle" direction="out" />
+ <arg type="i" name="dev_type" direction="out" />
+ <arg type="b" name="is_ndef_supported" direction="out" />
+ <arg type="y" name="ndef_card_state" direction="out" />
+ <arg type="u" name="max_data_size" direction="out" />
+ <arg type="u" name="actual_data_size" direction="out" />
+ <arg type="u" name="number_of_keys" direction="out" />
+ <arg type="a(y)" name="target_info_values" direction="out" />
+ <arg type="a(y)" name="raw_data" direction="out" />
+ </method>
+
+ <!--
+ GetTagetHandle
+ -->
+ <method name="GetCurrentTargetHandle">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="b" name="is_connected" direction="out" />
+ <arg type="u" name="handle" direction="out" />
+ <arg type="i" name="dev_type" direction="out" />
+ </method>
+
+ <!--
+ TagDiscovered
+ -->
+ <signal name="TagDiscovered">
+ <arg type="u" name="handle" />
+ <arg type="i" name="dev_type" />
+ <arg type="b" name="is_ndef_supported" />
+ <arg type="y" name="ndef_card_state" />
+ <arg type="u" name="max_data_size" />
+ <arg type="u" name="actual_data_size" />
+ <arg type="u" name="number_of_keys" />
+ <arg type="a(y)" name="target_info_values" />
+ <arg type="a(y)" name="raw_data" />
+ </signal>
+
+ <!--
+ TagDetached
+ -->
+ <signal name="TagDetached">
+ <arg type="u" name="handle" />
+ <arg type="i" name="dev_type" />
+ </signal>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Ndef">
+ <!--
+ Read
+ -->
+ <method name="Read">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="a(y)" name="data" direction="out" />
+ </method>
+
+ <!--
+ Write
+ -->
+ <method name="Write">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ MakeReadOnly
+ -->
+ <method name="MakeReadOnly">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Format
+ -->
+ <method name="Format">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="key" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Llcp">
+ <!--
+ Config
+ -->
+ <method name="Config">
+ <arg type="(qqyy)" name="config" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ </method>
+ <!--
+ Listen
+ -->
+ <method name="Listen">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="q" name="miu" direction="in" />
+ <arg type="y" name="rw" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="y" name="sap" direction="in" />
+ <arg type="s" name="service_name" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ <arg type="u" name="oal_socket" direction="out" />
+ </method>
+
+ <!--
+ Connect
+ -->
+ <method name="Connect">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="q" name="miu" direction="in" />
+ <arg type="y" name="rw" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="s" name="service_name" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ <arg type="u" name="oal_socket" direction="out" />
+ </method>
+
+ <!--
+ ConnectSap
+ -->
+ <method name="ConnectSap">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="q" name="miu" direction="in" />
+ <arg type="y" name="rw" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="y" name="sap" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ <arg type="u" name="oal_socket" direction="out" />
+ </method>
+
+ <!--
+ Send
+ -->
+ <method name="Send">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ </method>
+
+ <!--
+ SendTo
+ -->
+ <method name="SendTo">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="y" name="sap" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ </method>
+
+ <!--
+ Receive
+ -->
+ <method name="Receive">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="u" name="request_length" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="a(y)" name="data" direction="out" />
+ </method>
+
+ <!--
+ ReceiveFrom
+ -->
+ <method name="ReceiveFrom">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="u" name="request_length" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="y" name="sap" direction="out" />
+ <arg type="a(y)" name="data" direction="out" />
+ </method>
+
+ <!--
+ Close
+ -->
+ <method name="Close">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ </method>
+
+ <!--
+ Disconnect
+ -->
+ <method name="Disconnect">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="client_socket" direction="in" />
+ <arg type="u" name="oal_socket" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="u" name="client_socket" direction="out" />
+ </method>
+
+ <!--
+ Error
+ -->
+ <signal name="Error">
+ <arg type="u" name="handle" />
+ <arg type="u" name="client_socket" />
+ <arg type="u" name="oal_socket" />
+ <arg type="i" name="error" />
+ </signal>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.P2p">
+ <!--
+ Send
+ -->
+ <method name="Send">
+ <arg type="i" name="type" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Detached
+ -->
+ <signal name="Detached" />
+
+ <!--
+ Discovered
+ -->
+ <signal name="Discovered">
+ <arg type="u" name="handle" />
+ </signal>
+
+ <!--
+ Receive
+ -->
+ <signal name="Received">
+ <arg type="a(y)" name="data" />
+ </signal>
+
+ </interface>
+ <interface name="org.tizen.NetNfcService.Popup">
+ <!--
+ Set
+ -->
+ <method name="Set">
+ <arg type="b" name="state" direction="in" />
+ <arg type="i" name="focus_state" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ </method>
+
+ <!--
+ Get
+ -->
+ <method name="Get">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="b" name="state" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.SecureElement">
+ <!--
+ Set
+ -->
+ <method name="Set">
+ <arg type="i" name="type" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ OpenSecureElement
+ -->
+ <method name="OpenSecureElement">
+ <arg type="i" name="type" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="u" name="handle" direction="out" />
+ </method>
+
+ <!--
+ CloseSecureElement
+ -->
+ <method name="CloseSecureElement">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ GetAtr
+ -->
+ <method name="GetAtr">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="a(y)" name="atr" direction="out" />
+ </method>
+
+ <!--
+ SendAPDU
+ -->
+ <method name="SendAPDU">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="a(y)" name="response" direction="out" />
+ </method>
+
+ <!--
+ EseDetected
+ -->
+ <signal name="EseDetected">
+ <arg type="u" name="handle" />
+ <arg type="i" name="se_type" />
+ <arg type="a(y)" name="data" />
+ </signal>
+
+ <!--
+ SeTypeChanged
+ -->
+ <signal name="SeTypeChanged">
+ <arg type="i" name="se_type" />
+ </signal>
+
+ <!--
+ TransactionEvent
+ -->
+ <signal name="TransactionEvent">
+ <arg type="i" name="se_type" />
+ <arg type="a(y)" name="aid" />
+ <arg type="a(y)" name="param" />
+ </signal>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Transceive">
+ <!--
+ TransceiveData
+ -->
+ <method name="TransceiveData">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="dev_type" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="a(y)" name="resp_data" direction="out" />
+ </method>
+ <!--
+ Transceive
+ -->
+ <method name="Transceive">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="dev_type" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Handover">
+ <!--
+ Request
+ -->
+ <method name="Request">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="event" direction="out" />
+ <arg type="i" name="carrier_type" direction="out" />
+ <arg type="a(y)" name="handover_data" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Test">
+ <!--
+ SimTest
+ -->
+ <method name="SimTest">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ PrbsTest
+ -->
+ <method name="PrbsTest">
+ <arg type="u" name="tech" direction="in" />
+ <arg type="u" name="rate" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ GetFirmwareVersion
+ -->
+ <method name="GetFirmwareVersion">
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="s" name="version" direction="out" />
+ </method>
+
+ <method name="SetEeData">
+ <arg type="u" name="mode" direction="in" />
+ <arg type="u" name="reg_id" direction="in" />
+ <arg type="a(y)" name="data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.tizen.NetNfcService.Snep">
+ <!--
+ Register Server
+ -->
+ <method name="ServerRegister">
+ <arg type="u" name="sap" direction="in" />
+ <arg type="s" name="san" direction="in" />
+ <arg type="u" name="user_data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Unregister Server
+ -->
+ <method name="ServerUnregister">
+ <arg type="u" name="sap" direction="in" />
+ <arg type="s" name="san" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Start Server
+ -->
+ <method name="ServerStart">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="sap" direction="in" />
+ <arg type="s" name="san" direction="in" />
+ <arg type="u" name="user_data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ Start Client
+ -->
+ <method name="ClientStart">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="sap" direction="in" />
+ <arg type="s" name="san" direction="in" />
+ <arg type="u" name="user_data" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ ClientRequest
+ -->
+ <method name="ClientRequest">
+ <arg type="u" name="snep_handle" direction="in" />
+ <arg type="u" name="type" direction="in" />
+ <arg type="a(y)" name="ndef_msg" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ <arg type="u" name="type" direction="out" />
+ <arg type="a(y)" name="data" direction="out" />
+ </method>
+
+ <!--
+ StopService
+ -->
+ <method name="StopSnep">
+ <arg type="u" name="handle" direction="in" />
+ <arg type="u" name="snep_handle" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
+ SnepEvent
+ -->
+ <signal name="SnepEvent">
+ <arg type="u" name="handle" />
+ <arg type="u" name="event" />
+ <arg type="i" name="result" />
+ <arg type="a(y)" name="ndef_msg" />
+ <arg type="u" name="user_data" />
+ </signal>
+ </interface>
+
+</node>
// platform header
#include <bluetooth-api.h>
#include <vconf.h>
-#include <app_manager.h>
// nfc-manager header
-#include "net_nfc_util_private.h"
-#include "net_nfc_debug_private.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_debug_internal.h"
#include "net_nfc_oem_controller.h"
#include "net_nfc_util_defines.h"
#define NET_NFC_MANAGER_NAME "nfc-manager-daemon"
static const char *log_tag = LOG_CLIENT_TAG;
extern char *__progname;
-FILE *nfc_log_file = NULL;
+FILE *nfc_log_file;
const char *net_nfc_get_log_tag()
{
{
if (mem == NULL)
{
- DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in mem free util, mem is NULL", filename, line);
+ SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem free util, mem is NULL", filename, line);
return;
}
if (*mem == NULL)
{
- DEBUG_MSG("FILE: %s, LINE:%d, Invalid Parameter in mem free util, *mem is NULL", filename, line);
+ SECURE_LOGD("FILE: %s, LINE:%d, Invalid Parameter in mem free util, *mem is NULL", filename, line);
return;
}
- free(*mem);
+ g_free(*mem);
*mem = NULL;
}
{
if (mem == NULL || size <= 0)
{
- DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in mem alloc util, mem [%p], size [%d]", filename, line, mem, size);
+ SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in mem alloc util, mem [%p], size [%d]", filename, line, mem, size);
return;
}
if (*mem != NULL)
{
- DEBUG_MSG("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *mem);
+ SECURE_LOGD("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *mem);
}
- *mem = calloc(1, size);
+ *mem = g_malloc0(size);
if (*mem == NULL)
{
- DEBUG_ERR_MSG("FILE: %s, LINE:%d, Allocation is failed, size [%d]", filename, line, size);
+ SECURE_LOGD("FILE: %s, LINE:%d, Allocation is failed, size [%d]", filename, line, size);
}
}
{
if (output == NULL || origin == NULL)
{
- DEBUG_MSG("FILE: %s, LINE:%d, Invalid parameter in strdup, output [%p], origin [%p]", filename, line, output, origin);
+ SECURE_LOGD("FILE: %s, LINE:%d, Invalid parameter in strdup, output [%p], origin [%p]", filename, line, output, origin);
return;
}
if (*output != NULL)
{
- DEBUG_MSG("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *output);
+ SECURE_LOGD("FILE: %s, LINE:%d, WARNING: Pointer is not NULL, mem [%p]", filename, line, *output);
}
- *output = strdup(origin);
+ *output = g_strdup(origin);
if (*output == NULL)
{
- DEBUG_ERR_MSG("FILE: %s, LINE:%d, strdup failed", filename, line);
+ SECURE_LOGD("FILE: %s, LINE:%d, strdup failed", filename, line);
}
}
return;
_net_nfc_util_free_mem(data->buffer);
-}
-
-NET_NFC_EXPORT_API void net_nfc_util_mem_free_detail_msg(int msg_type, int message, void *data)
-{
- if (data == NULL)
- return;
-
- if (msg_type == NET_NFC_UTIL_MSG_TYPE_REQUEST)
- {
- _net_nfc_util_free_mem(data);
- }
- else if (msg_type == NET_NFC_UTIL_MSG_TYPE_RESPONSE)
- {
- switch (message)
- {
- case NET_NFC_MESSAGE_READ_NDEF :
- {
- net_nfc_response_read_ndef_t *msg = (net_nfc_response_read_ndef_t *)data;
- _net_nfc_util_free_mem(msg->data.buffer);
- }
- break;
- case NET_NFC_MESSAGE_TRANSCEIVE :
- {
- net_nfc_response_transceive_t *msg = (net_nfc_response_transceive_t *)data;
- _net_nfc_util_free_mem(msg->data.buffer);
- }
- break;
- case NET_NFC_MESSAGE_TAG_DISCOVERED :
- {
- net_nfc_response_tag_discovered_t *msg = (net_nfc_response_tag_discovered_t *)data;
- _net_nfc_util_free_mem(msg->target_info_values.buffer);
- _net_nfc_util_free_mem(msg->raw_data.buffer);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE :
- {
- net_nfc_response_receive_socket_t *msg = (net_nfc_response_receive_socket_t *)data;
- _net_nfc_util_free_mem(msg->data.buffer);
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_RECEIVE :
- {
- net_nfc_response_p2p_receive_t *msg = (net_nfc_response_p2p_receive_t *)data;
- _net_nfc_util_free_mem(msg->data.buffer);
- }
- break;
-
- case NET_NFC_MESSAGE_SEND_APDU_SE :
- {
- net_nfc_response_send_apdu_t *msg = (net_nfc_response_send_apdu_t *)data;
- _net_nfc_util_free_mem(msg->data.buffer);
- }
- break;
-
- default :
- break;
- }
-
- _net_nfc_util_free_mem(data);
- }
- else
- {
- DEBUG_MSG("unknown message type");
- }
+ data->length = 0;
}
net_nfc_conn_handover_carrier_state_e net_nfc_util_get_cps(net_nfc_conn_handover_carrier_type_e carrier_type)
return schema[index];
}
-pid_t net_nfc_util_get_current_app_pgid(pid_t pid)
-{
- char *app_id = NULL;
- app_context_h context = NULL;
- pid_t pgid = NULL;
-
- app_manager_get_app_id(pid, &app_id);
- app_manager_get_app_context(app_id, &context);
-
- app_context_get_pid(context, &pgid);
-
- free(app_id);
- app_context_destroy(context);
-
- return pgid;
-}
-
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// libc header
+
+// platform header
+
+// nfc-manager header
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+
+void net_nfc_util_gdbus_variant_to_buffer(GVariant *variant, uint8_t **buffer,
+ size_t *length)
+{
+ GVariantIter *iter;
+ guint8 *buf = NULL;
+ guint size = 0;
+
+ if (variant == NULL)
+ return;
+
+ g_variant_get(variant, "a(y)", &iter);
+
+ size = g_variant_iter_n_children(iter);
+ buf = g_new0(guint8, size);
+ if (buf != NULL)
+ {
+ guint8 element;
+ guint i;
+
+ i = 0;
+ while (g_variant_iter_loop(iter, "(y)", &element))
+ {
+ *(buf + i) = element;
+ i++;
+ }
+
+ g_variant_iter_free(iter);
+
+ if (length)
+ *length = size;
+
+ if (buffer)
+ *buffer = buf;
+ else
+ g_free(buf);
+ }
+}
+
+data_s *net_nfc_util_gdbus_variant_to_data(GVariant *variant)
+{
+ GVariantIter *iter;
+ guint8 *buf = NULL;
+ guint size = 0;
+ data_s *result = NULL;
+
+ if (variant == NULL)
+ return result;
+
+ g_variant_get(variant, "a(y)", &iter);
+
+ size = g_variant_iter_n_children(iter);
+ buf = g_new0(guint8, size);
+ if (buf != NULL)
+ {
+ guint i;
+ guint8 element;
+
+ i = 0;
+ while (g_variant_iter_loop(iter, "(y)", &element))
+ {
+ *(buf + i) = element;
+ i++;
+ }
+
+ g_variant_iter_free(iter);
+
+ result = g_new0(data_s, 1);
+ if (result != NULL)
+ {
+ result->buffer = buf;
+ result->length = size;
+ }
+ else
+ {
+ g_free(buf);
+ }
+ }
+
+ return result;
+}
+
+void net_nfc_util_gdbus_variant_to_data_s(GVariant *variant, data_s *data)
+{
+ GVariantIter *iter;
+
+ guint8 element;
+ guint8 *buf = NULL;
+
+ guint size = 0;
+
+ if (data == NULL)
+ return;
+
+ data->buffer = NULL;
+ data->length = 0;
+
+ if (variant == NULL)
+ {
+ return;
+ }
+
+ g_variant_get(variant, "a(y)", &iter);
+
+ size = g_variant_iter_n_children(iter);
+ buf = g_new0(guint8, size);
+ if (buf != NULL)
+ {
+ guint i = 0;
+
+ while (g_variant_iter_loop(iter, "(y)", &element))
+ {
+ *(buf + i) = element;
+ i++;
+ }
+
+ g_variant_iter_free(iter);
+
+ data->length = size;
+ data->buffer = buf;
+ }
+}
+
+GVariant *net_nfc_util_gdbus_buffer_to_variant(const uint8_t *buffer,
+ size_t length)
+{
+ GVariantBuilder builder;
+
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
+
+ if (buffer && length > 0)
+ {
+ int i;
+
+ for(i = 0; i < length; i++)
+ g_variant_builder_add(&builder, "(y)", *(buffer + i));
+ }
+
+ return g_variant_builder_end(&builder);
+}
+
+GVariant *net_nfc_util_gdbus_data_to_variant(const data_s *data)
+{
+ if (data != NULL)
+ {
+ return net_nfc_util_gdbus_buffer_to_variant(data->buffer,
+ data->length);
+ }
+ else
+ {
+ return net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ }
+}
#include <glib.h>
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
#include "net_nfc_util_defines.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_ndef_record.h"
#include "net_nfc_util_ndef_message.h"
#include "net_nfc_util_handover.h"
elem->attribute = attribute;
elem->length = size;
elem->is_group = false;
- _net_nfc_util_alloc_mem(elem->data, size);
+ _net_nfc_util_alloc_mem(elem->data, size);
if (elem->data == NULL)
{
_net_nfc_util_free_mem(elem);
switch ((*config)->type)
{
case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
- case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
result = __net_nfc_get_list_from_serial_for_wifi((GList **)&((*config)->data), record->payload_s.buffer, record->payload_s.length);
break;
case NET_NFC_CONN_HANDOVER_CARRIER_BT :
}
payload.length = size;
- uint8_t version = ((CONN_HANOVER_MAJOR_VER << 4) & 0xf0) | (CONN_HANOVER_MINOR_VER & 0x0f);
+ uint8_t version = CH_VERSION;
(payload.buffer)[0] = version;
(payload.buffer)++;
(payload.buffer)--;
(payload.length)++;
- type.buffer = (uint8_t *)CONN_HANDOVER_REQ_RECORD_TYPE;
- type.length = strlen(CONN_HANDOVER_REQ_RECORD_TYPE);
+ type.buffer = (uint8_t *)CH_REQ_RECORD_TYPE;
+ type.length = strlen(CH_REQ_RECORD_TYPE);
net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);
net_nfc_util_append_record(*message, record);
}
payload.length = (uint32_t)1;
- (payload.buffer)[0] = ((CONN_HANOVER_MAJOR_VER << 4) & 0xf0) | (CONN_HANOVER_MINOR_VER & 0x0f);
+ (payload.buffer)[0] = CH_VERSION;
- type.buffer = (uint8_t*)CONN_HANDOVER_SEL_RECORD_TYPE;
- type.length = strlen(CONN_HANDOVER_SEL_RECORD_TYPE);
+ type.buffer = (uint8_t*)CH_SEL_RECORD_TYPE;
+ type.length = strlen(CH_SEL_RECORD_TYPE);
net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &record);
net_nfc_util_append_record(*message, record);
return NET_NFC_INVALID_FORMAT;
}
- if (strncmp((char*)(inner_record->type_s.buffer), CONN_HANDOVER_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0
- && strncmp((char*)(inner_record->type_s.buffer), CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)
+ if (strncmp((char*)(inner_record->type_s.buffer), CH_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0
+ && strncmp((char*)(inner_record->type_s.buffer), CH_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)
{
// This message is not connection handover message
return NET_NFC_INVALID_FORMAT;
return NET_NFC_INVALID_FORMAT;
}
- if (strncmp((char *)(inner_record->type_s.buffer), CONN_HANDOVER_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0
- && strncmp((char *)(inner_record->type_s.buffer), CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)
+ if (strncmp((char *)(inner_record->type_s.buffer), CH_REQ_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0
+ && strncmp((char *)(inner_record->type_s.buffer), CH_SEL_RECORD_TYPE, (size_t)(inner_record->type_s.length)) != 0)
{
// This message is not connection handover message
DEBUG_ERR_MSG("unknown type [%s]", inner_record->type_s.buffer);
data_s type = { NULL, 0 };
int config_ref_count = 0;
net_nfc_error_e error;
- char buffer[256] = { 0, };
+ uint8_t buffer[256] = { 0, };
+#if 0
+ int i;
+#endif
+ int offset;
+ uint8_t id;
if (message == NULL || record == NULL)
{
if ((error = net_nfc_util_create_ndef_message(&inner_msg)) != NET_NFC_OK)
{
- DEBUG_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
+ DEBUG_ERR_MSG("net_nfc_util_create_ndef_message failed [%d]", error);
return error;
}
}
else if (strncmp((char *)last_rec->type_s.buffer, ALTERNATIVE_RECORD_TYPE, (size_t)last_rec->type_s.length) == 0)
{
- strncpy(buffer, (char *)((last_rec->payload_s.buffer) + 2), (size_t)(last_rec->payload_s.buffer[1]));
- config_ref_count = atoi(buffer);
+ memcpy(buffer, last_rec->payload_s.buffer, last_rec->payload_s.length);
+ config_ref_count = last_rec->payload_s.buffer[1];
}
}
else
{
/* selector record type can include empty inner message. so that case, we will continue */
- if (memcmp((char *)message->records->type_s.buffer, CONN_HANDOVER_SEL_RECORD_TYPE, (size_t)message->records->type_s.length) != 0)
+ if (message->records != NULL &&
+ memcmp((char *)message->records->type_s.buffer, CH_SEL_RECORD_TYPE, (size_t)message->records->type_s.length) != 0)
{
DEBUG_ERR_MSG("ERROR [%d]", error);
type.length = strlen(ALTERNATIVE_RECORD_TYPE);
config_ref_count++;
- snprintf(buffer, sizeof(buffer), " %d ", config_ref_count); /* total size of payload is generally greater than 4. this is a trick :)*/
+ offset = 0;
+// id = '0' + config_ref_count;
+ id = 'b';
+
+ /* carrier flag */
+ buffer[offset++] = (uint8_t)(power_status & 0x3); /* first byte, power status */
- payload.length = strlen(buffer);
- payload.buffer = (uint8_t *)buffer;
- payload.buffer[0] = (uint8_t)(power_status & 0x3); /* first byte, power status */
- payload.buffer[1] = (uint8_t)payload.length - 2; /* payload length except 2 bytes (power status and itself) */
+ /* carrier data ref. len */
+ buffer[offset++] = config_ref_count;
+
+ /* carrier data ref. */
+ offset += (config_ref_count - 1);
+ buffer[offset++] = id;
+
+ /* FIXME */
+ /* aux data ref. len */
+ buffer[offset++] = 0;
+#if 0 /* FIXME */
+ /* carrier data ref. */
+ for (i = 0; i < 0; i++)
+ {
+ buffer[offset++] = 0;
+ }
+#endif
+ payload.buffer = buffer;
+ payload.length = offset;
error = net_nfc_util_create_record(NET_NFC_RECORD_WELL_KNOWN_TYPE, &type, NULL, &payload, &carrier_rec);
if (error != NET_NFC_OK)
}
/* set record id to record that will be appended to ndef message */
- error = net_nfc_util_set_record_id((ndef_record_s *)record, (uint8_t *)(buffer + 2), payload.length - 2);
+ error = net_nfc_util_set_record_id((ndef_record_s *)record, &id, sizeof(id));
if (error != NET_NFC_OK)
{
DEBUG_ERR_MSG("net_nfc_util_set_record_id failed [%d]", error);
#include <string.h>
#include <fcntl.h>
-#include "net_nfc_debug_private.h"
+#include "net_nfc_debug_internal.h"
int net_nfc_util_get_va_list_length(va_list list)
{
*/
-#include "net_nfc_debug_private.h"
+#include "net_nfc_debug_internal.h"
#include "net_nfc_util_defines.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_ndef_message.h"
#include "net_nfc_util_ndef_record.h"
int total = 0;
if (message == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
+ return 0;
current = message->records;
current = current->next;
}
- DEBUG_MSG("total byte length = [%d]", total);
-
return total;
}
{
memcpy(buffer, current->id_s.buffer, current->id_s.length);
buffer[current->id_s.length] = '\0';
- DEBUG_MSG("ID: %s\n", buffer);
+ SECURE_LOGD("ID: %s\n", buffer);
}
if (current->payload_s.buffer != NULL)
{
net_nfc_error_e net_nfc_util_create_ndef_message(ndef_message_s **ndef_message)
{
- if (ndef_message == NULL)
- {
+ if (ndef_message == NULL) {
return NET_NFC_NULL_PARAMETER;
}
_net_nfc_util_alloc_mem(*ndef_message, sizeof(ndef_message_s));
+ if (*ndef_message == NULL) {
+ return NET_NFC_ALLOC_FAIL;
+ }
return NET_NFC_OK;
}
net_nfc_error_e net_nfc_util_search_record_by_type(ndef_message_s *ndef_message, net_nfc_record_tnf_e tnf, data_s *type, ndef_record_s **record)
{
int idx = 0;
- ndef_record_s *record_private;
+ ndef_record_s *tmp_record;
uint32_t type_length;
uint8_t *buf;
}
}
- record_private = ndef_message->records;
+ tmp_record = ndef_message->records;
for (; idx < ndef_message->recordCount; idx++)
{
- if (record_private == NULL)
+ if (tmp_record == NULL)
{
*record = NULL;
return NET_NFC_INVALID_FORMAT;
}
- if (record_private->TNF == tnf &&
- type_length == record_private->type_s.length &&
- memcmp(buf, record_private->type_s.buffer, type_length) == 0)
+ if (tmp_record->TNF == tnf &&
+ type_length == tmp_record->type_s.length &&
+ memcmp(buf, tmp_record->type_s.buffer, type_length) == 0)
{
- *record = record_private;
+ *record = tmp_record;
return NET_NFC_OK;
}
- record_private = record_private->next;
+ tmp_record = tmp_record->next;
}
return NET_NFC_NO_DATA_FOUND;
* limitations under the License.
*/
-#include "net_nfc_debug_private.h"
+#include "net_nfc_debug_internal.h"
#include "net_nfc_util_defines.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_ndef_message.h"
#include "net_nfc_util_ndef_record.h"
{
uint32_t RecordLength = 1;
+ if (Record == NULL)
+ return 0;
+
/* Type length is present only for following TNF
NET_NFC_TNF_NFCWELLKNOWN
NET_NFC_TNF_MEDIATYPE
#include <openssl/pkcs12.h>
#include <openssl/pem.h>
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_util_openssl_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_openssl_internal.h"
//static X509 *_load_certificate_from_file(const char *file)
//{
#include <sys/param.h>
-#include "net_nfc_debug_private.h"
+#include "net_nfc_debug_internal.h"
#include "net_nfc_util_defines.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_ndef_message.h"
#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_util_openssl_private.h"
+#include "net_nfc_util_openssl_internal.h"
#include "net_nfc_util_sign_record.h"
#define IS_SIGN_RECORD(__x) \
/* parse certificate chain info */
chain_info = (net_nfc_certificate_chain_s *)__NEXT_SUB_FIELD(&(sign_info->signature));
- DEBUG_MSG("certificate URI present? : %s", chain_info->uri_present ? "true" : "false");
+ SECURE_LOGD("certificate URI present? : %s", chain_info->uri_present ? "true" : "false");
DEBUG_MSG("certificate format : %d", chain_info->cert_format);
DEBUG_MSG("number of certificates : %d", chain_info->num_of_certs);
}
else
{
+ if(buffer != NULL)
+ {
+ _net_nfc_util_free_mem(buffer);
+ }
DEBUG_ERR_MSG("_get_records_data_buffer failed");
}
prefix=/usr
exec_prefix=/usr/bin
-libdir=@LIB_INSTALL_DIR@
+libdir=/usr/lib
includedir=/usr/include/nfc-common-lib
Name: nfc-common-lib
Description: NFC Common Library
Version: 1.0
Requires:
-Libs: -L@LIB_INSTALL_DIR@ -lnfc-common-lib
+Libs: -L/usr/lib -lnfc-common-lib
Cflags: -I/usr/include/nfc-common-lib
SET(NFC_MANAGER_DAEMON "nfc-manager-daemon")
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../commonlib/include)
+include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/)
+include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ MANAGER_SRCS)
-ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"")
+
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
INCLUDE(FindPkgConfig)
-pkg_check_modules(manager_pkges REQUIRED aul glib-2.0 gobject-2.0 security-server dbus-glib-1 vconf dlog tapi appsvc libcurl bluetooth-api heynoti smartcard-service smartcard-service-common libssl pmapi svi capi-media-wav-player pkgmgr pkgmgr-info ecore-x)
-
+pkg_check_modules(manager_pkges REQUIRED aul glib-2.0 gio-unix-2.0 security-server vconf dlog tapi appsvc libcurl bluetooth-api libssl svi capi-media-wav-player pkgmgr pkgmgr-info ecore-x pmapi)
FOREACH(flag ${manager_pkges_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
# this for NFC flag
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
ENDIF()
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-#ADD_DEFINITIONS("-DSLP_DEBUG")
-ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")
-
-ADD_DEFINITIONS("-DNFC_FIRMWARE_UPDATE")
-ADD_DEFINITIONS("-DNFC_DEBUG_USE_DLOG -D_GNU_SOURCE")
-ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN")
-ADD_DEFINITIONS("-DUSE_IPC_EPOLL -DUSE_EPOLL_TIMEOUT")
-ADD_DEFINITIONS("-DLLCP_MODE")
-ADD_DEFINITIONS("-DNFC_APP_SUPPORTED")
-ADD_DEFINITIONS("-DBROADCAST_MESSAGE")
-ADD_DEFINITIONS("-DSAVE_TARGET_INFO_IN_CC")
-ADD_DEFINITIONS("-DSECURITY_SERVER")
-#ADD_DEFINITIONS("-DG_MAIN_LOOP")
-#ADD_DEFINITIONS("-DUSE_ECORE_MAIN_LOOP")
-ADD_DEFINITIONS("-DUSE_GLIB_MAIN_LOOP")
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+ADD_DEFINITIONS("-DNFC_MANAGER_MODULEDIR=\"${MODULEDIR}\"")
+
ADD_DEFINITIONS("-DUSE_FULL_URI")
-# add temporary
-ADD_DEFINITIONS("-D_TIZEN_OPEN")
+#ADD_DEFINITIONS("-DESE_ALWAYS_ON")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
-FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
-EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=nfc_service ${CMAKE_CURRENT_SOURCE_DIR}/nfc-service.xml --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/include/nfc-service-glue.h")
-EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=nfc_service ${CMAKE_CURRENT_SOURCE_DIR}/nfc-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/nfc-service-binding.h")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
ADD_EXECUTABLE(${NFC_MANAGER_DAEMON} ${MANAGER_SRCS})
-
-TARGET_LINK_LIBRARIES(${NFC_MANAGER_DAEMON} ${manager_pkges_LDFLAGS} "-lpthread -lrt -pie -ldl -L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/commonlib/ -lnfc-common-lib -L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/clientlib/ -lnfc")
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.nfc_service.service DESTINATION share/dbus-1/services)
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sounds DESTINATION /usr/share/nfc-manager-daemon)
+TARGET_LINK_LIBRARIES(${NFC_MANAGER_DAEMON} ${manager_pkges_LDFLAGS} pthread dl rt nfc-common-lib nfc)
+LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib ${CMAKE_BUILD_DIR}/src/clientlib)
INSTALL(TARGETS ${NFC_MANAGER_DAEMON} DESTINATION bin)
-
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.NetNfcService.service DESTINATION share/dbus-1/services)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nfc-manager.xml DESTINATION share/packages)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sounds DESTINATION share/nfc-manager-daemon)
/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_APP_UTIL_INTERNAL_H__
+#define __NET_NFC_APP_UTIL_INTERNAL_H__
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_APP_UTIL_H
-#define NET_NFC_APP_UTIL_H
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_private.h"
#include <aul.h>
+#include "net_nfc_typedef_internal.h"
#ifndef MESSAGE_STORAGE
#define MESSAGE_STORAGE "/opt/share/service/nfc-manager"
int net_nfc_app_util_decode_base64(const char *buffer, uint32_t buf_len, uint8_t *result, uint32_t *res_len);
bool net_nfc_app_util_check_launch_state();
-#endif
+#endif //__NET_NFC_APP_UTIL_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_CONTROLLER_INTERNAL_H__
+#define __NET_NFC_CONTROLLER_INTERNAL_H__
+
+#include "net_nfc_typedef_internal.h"
+
+typedef struct _socket_info_t
+{
+ net_nfc_llcp_socket_t socket;
+ net_nfc_service_llcp_cb err_cb;
+ net_nfc_service_llcp_cb work_cb;
+ void *err_param;
+ void *work_param;
+}
+socket_info_t;
+
+/* common api */
+void *net_nfc_controller_onload(void);
+bool net_nfc_controller_unload(void *handle);
+bool net_nfc_controller_init(net_nfc_error_e *result);
+bool net_nfc_controller_deinit(void);
+bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e* result);
+bool net_nfc_controller_unregister_listener(void);
+bool net_nfc_controller_support_nfc(net_nfc_error_e *result);
+bool net_nfc_controller_get_firmware_version(data_s **data, net_nfc_error_e *result);
+bool net_nfc_controller_check_firmware_version(net_nfc_error_e *result);
+bool net_nfc_controller_update_firmware(net_nfc_error_e *result);
+bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result);
+bool net_nfc_controller_configure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result);
+bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_check_ndef(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result);
+bool net_nfc_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result);
+bool net_nfc_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result);
+bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_format_ndef(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result);
+bool net_nfc_controller_transceive (net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result);
+bool net_nfc_controller_exception_handler(void);
+bool net_nfc_controller_is_ready(net_nfc_error_e *result);
+
+/* llcp api */
+bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_send(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param);
+bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_get_remote_config (net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
+bool net_nfc_controller_llcp_get_remote_socket_info (net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result);
+
+void net_nfc_controller_llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_incoming_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_connected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_disconnected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_received_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+void net_nfc_controller_llcp_sent_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param);
+
+/* secure element api */
+bool net_nfc_controller_secure_element_open(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result);
+bool net_nfc_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, data_s **atr, net_nfc_error_e *result);
+bool net_nfc_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result);
+bool net_nfc_controller_secure_element_close(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
+bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result);
+bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e* result);
+
+/* test api */
+bool net_nfc_controller_sim_test(net_nfc_error_e *result);
+bool net_nfc_controller_prbs_test(net_nfc_error_e *result , uint32_t tech , uint32_t rate);
+bool net_nfc_controller_test_mode_on(net_nfc_error_e *result);
+bool net_nfc_controller_test_mode_off(net_nfc_error_e *result);
+bool net_nfc_test_sim(void);
+bool net_nfc_controller_eedata_register_set(net_nfc_error_e *result , uint32_t mode , uint32_t reg_id , data_s *data);
+
+socket_info_t *_get_socket_info(net_nfc_llcp_socket_t socket);
+socket_info_t *_add_socket_info(net_nfc_llcp_socket_t socket);
+
+#endif //__NET_NFC_CONTROLLER_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_CONTROLLER_H
-#define NET_NFC_CONTROLLER_H
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_private.h"
-
-/* common api */
-void* net_nfc_controller_onload(void);
-bool net_nfc_controller_unload(void* handle);
-bool net_nfc_controller_init (net_nfc_error_e* result);
-bool net_nfc_controller_deinit (void);
-bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e* result);
-bool net_nfc_controller_unregister_listener(void);
-bool net_nfc_controller_get_firmware_version(data_s **data, net_nfc_error_e *result);
-bool net_nfc_controller_check_firmware_version(net_nfc_error_e* result);
-bool net_nfc_controller_update_firmware(net_nfc_error_e* result);
-bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result);
-bool net_nfc_controller_confiure_discovery (net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result);
-bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result);
-bool net_nfc_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result);
-bool net_nfc_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result);
-bool net_nfc_controller_check_ndef(net_nfc_target_handle_s* handle, uint8_t *ndef_card_state, int* max_data_size, int* real_data_size, net_nfc_error_e* result);
-bool net_nfc_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result);
-bool net_nfc_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result);
-bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s* handle, net_nfc_error_e* result);
-bool net_nfc_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result);
-bool net_nfc_controller_transceive (net_nfc_target_handle_s* handle, net_nfc_transceive_info_s* info, data_s** data, net_nfc_error_e* result);
-bool net_nfc_controller_exception_handler(void);
-bool net_nfc_controller_is_ready(net_nfc_error_e* result);
-
-/* llcp api */
-bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e * result);
-bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result);
-bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s * handle, net_nfc_error_e* result);
-bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t* socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result);
-bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t* service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result);
-bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s * handle, net_nfc_llcp_socket_t socket, uint8_t* service_access_name, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s * handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s * handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result);
-bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_send(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, uint8_t service_access_point, net_nfc_error_e* result, void * user_param);
-bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result);
-bool net_nfc_controller_llcp_get_remote_config (net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result);
-bool net_nfc_controller_llcp_get_remote_socket_info (net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s * option, net_nfc_error_e* result);
-
-/* secure element api */
-bool net_nfc_controller_secure_element_open(net_nfc_secure_element_type_e element_type, net_nfc_target_handle_s **handle, net_nfc_error_e *result);
-bool net_nfc_controller_secure_element_get_atr(net_nfc_target_handle_s *handle, data_s **atr, net_nfc_error_e *result);
-bool net_nfc_controller_secure_element_send_apdu(net_nfc_target_handle_s *handle, data_s *command, data_s **response, net_nfc_error_e *result);
-bool net_nfc_controller_secure_element_close(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
-bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result);
-bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e* result);
-
-/* test api */
-bool net_nfc_controller_sim_test(net_nfc_error_e* result);
-bool net_nfc_controller_prbs_test(net_nfc_error_e* result , uint32_t tech , uint32_t rate);
-
-bool net_nfc_controller_test_mode_on(net_nfc_error_e* result);
-bool net_nfc_controller_test_mode_off(net_nfc_error_e* result);
-bool net_nfc_test_sim(void);
-
-bool net_nfc_controller_support_nfc(net_nfc_error_e* result);
-
-bool net_nfc_controller_eedata_register_set(net_nfc_error_e *result , uint32_t mode , uint32_t reg_id , data_s *data);
-#endif
-
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#ifndef __NET_NFC_MANAGER_H__
+#define __NET_NFC_MANAGER_H__
-#ifndef __NET_NFC_CLIENT_UTIL_PRIVATE__
-#define __NET_NFC_CLIENT_UTIL_PRIVATE__
-
-#endif
+void net_nfc_manager_quit();
+#endif //__NET_NFC_MANAGER_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MANAGERDBUS_H_
-#define MANAGERDBUS_H_
-
-/* standard library header */
-#include <glib-object.h>
-
-/* SLP library header */
-
-/* local header */
-
-typedef struct _Nfc_Service Nfc_Service;
-typedef struct _Nfc_ServiceClass Nfc_ServiceClass;
-
-#define NFC_SERVICE_NAME "org.tizen.nfc_service"
-#define NFC_SERVICE_PATH "/org/tizen/nfc_service"
-
-GType nfc_service_get_type(void);
-
-struct _Nfc_Service
-{
- GObject parent;
- int status;
-};
-
-struct _Nfc_ServiceClass
-{
- GObjectClass parent;
-};
-
-#define NFC_SERVICE_TYPE (nfc_service_get_type ())
-#define NFC_SERVICE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), NFC_SERVICE_TYPE, Nfc_Service))
-#define NFC_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NFC_SERVICE_TYPE, Nfc_Service_Class))
-#define IS_NFC_SERVICE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), NFC_SERVICE_TYPE))
-#define IS_NFC_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NFC_SERVICE_TYPE))
-#define NFC_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NFC_SERVICE_TYPE, Nfc_Service_Class))
-
-typedef enum
-{
- NFC_SERVICE_ERROR_INVALID_PRAM
-} Nfc_Service_Error;
-
-GQuark nfc_service_error_quark(void);
-#define NFC_SERVICE_ERROR nfc_service_error_quark ()
-
-/**
- * launch the nfc-manager
- */
-gboolean nfc_service_launch (Nfc_Service *nfc_service, const pid_t pid, guint *result_val, GError **error);
-gboolean nfc_service_terminate (Nfc_Service *nfc_service, guint *result_val, GError **error);
-
-#endif /* MANAGERDBUS_H_ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#ifndef __NET_NFC_MANAGER_UTIL_PRIVATE__
-#define __NET_NFC_MANAGER_UTIL_PRIVATE__
+#ifndef __NET_NFC_MANAGER_UTIL_INTERNAL_H__
+#define __NET_NFC_MANAGER_UTIL_INTERNAL_H__
#define NET_NFC_MANAGER_DATA_PATH "/opt/data/nfc-manager-daemon"
#define NET_NFC_MANAGER_DATA_PATH_MESSAGE "message"
#define NET_NFC_MANAGER_NDEF_FILE_NAME "ndef-message.txt"
#define NET_NFC_MANAGER_LLCP_CONFIG_FILE_NAME "nfc-manager-config.txt"
-#ifdef _TIZEN_OPEN
#define NET_NFC_MANAGER_SOUND_PATH_TASK_START "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
#define NET_NFC_MANAGER_SOUND_PATH_TASK_END "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
#define NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR "/usr/share/nfc-manager-daemon/sounds/Operation_sdk.wav"
-#else
-#define NET_NFC_MANAGER_SOUND_PATH_TASK_START "/usr/share/nfc-manager-daemon/sounds/NFC_start.wav"
-#define NET_NFC_MANAGER_SOUND_PATH_TASK_END "/usr/share/nfc-manager-daemon/sounds/NFC_end.wav"
-#define NET_NFC_MANAGER_SOUND_PATH_TASK_ERROR "/usr/share/nfc-manager-daemon/sounds/NFC_error.wav"
-#endif
#define BUFFER_LENGTH_MAX 1024
void net_nfc_manager_util_play_sound(net_nfc_sound_type_e sound_type);
-#endif
-
+#endif //__NET_NFC_MANAGER_UTIL_INTERNAL_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_H__
+#define __NET_NFC_SERVER_H__
+
+void net_nfc_server_gdbus_init(void);
+
+void net_nfc_server_gdbus_deinit(void);
+
+pid_t net_nfc_server_gdbus_get_pid(const char *name);
+
+#endif //__NET_NFC_SERVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_COMMON_H__
+#define __NET_NFC_SERVER_COMMON_H__
+
+#include <glib.h>
+
+#include "net_nfc_typedef.h"
+
+typedef void (*net_nfc_server_controller_func)(gpointer user_data);
+
+gboolean net_nfc_server_controller_thread_init(void);
+
+void net_nfc_server_controller_thread_deinit(void);
+
+void net_nfc_server_controller_init(void);
+#ifndef ESE_ALWAYS_ON
+void net_nfc_server_controller_deinit(void);
+#endif
+gboolean net_nfc_server_controller_async_queue_push(
+ net_nfc_server_controller_func func,
+ gpointer user_data);
+
+void net_nfc_server_restart_polling_loop(void);
+
+void net_nfc_server_set_state(guint32 state);
+
+void net_nfc_server_unset_state(guint32 state);
+
+guint32 net_nfc_server_get_state(void);
+
+#endif //__NET_NFC_SERVER_COMMON_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_CONTEXT_INTERNAL_H__
+#define __NET_NFC_SERVER_CONTEXT_INTERNAL_H__
+
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+typedef struct _net_nfc_client_context_info_t
+{
+ /* Permanent property */
+ char *id;
+ pid_t pid;
+ pid_t pgid;
+
+ /* changed by client state */
+ int ref_se;
+ client_state_e state;
+ net_nfc_launch_popup_state_e launch_popup_state;
+ net_nfc_launch_popup_state_e launch_popup_state_no_check;
+
+} net_nfc_client_context_info_t;
+
+typedef void (*net_nfc_server_gdbus_for_each_client_cb)(
+ net_nfc_client_context_info_t *client, void *user_param);
+
+void net_nfc_server_gdbus_init_client_context();
+
+void net_nfc_server_gdbus_deinit_client_context();
+
+bool net_nfc_server_gdbus_check_privilege(GDBusMethodInvocation *invocation,
+ GVariant *privilege,
+ const char *object,
+ const char *right);
+
+void net_nfc_server_gdbus_add_client_context(const char *id,
+ client_state_e state);
+
+void net_nfc_server_gdbus_cleanup_client_context(const char *id);
+
+net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context(
+ const char *id);
+
+size_t net_nfc_server_gdbus_get_client_count();
+
+void net_nfc_server_gdbus_for_each_client_context(
+ net_nfc_server_gdbus_for_each_client_cb cb,
+ void *user_param);
+
+bool net_nfc_server_gdbus_check_client_is_running(const char *id);
+
+client_state_e net_nfc_server_gdbus_get_client_state(
+ const char *id);
+
+void net_nfc_server_gdbus_set_client_state(const char *id,
+ client_state_e state);
+
+void net_nfc_server_gdbus_set_launch_state(const char *id,
+ net_nfc_launch_popup_state_e popup_state,
+ net_nfc_launch_popup_check_e check_foreground);
+
+net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_launch_state(
+ const char *id);
+
+net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_client_popup_state(
+ pid_t pid);
+
+void net_nfc_server_gdbus_increase_se_count(const char *id);
+void net_nfc_server_gdbus_decrease_se_count(const char *id);
+
+bool net_nfc_server_gdbus_is_server_busy();
+
+#endif //__NET_NFC_SERVER_CONTEXT_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef NET_NFC_SERVER_CONTEXT_H
-#define NET_NFC_SERVER_CONTEXT_H
-
-#include <unistd.h>
-
-#include "net_nfc_typedef_private.h"
-
-/* define */
-typedef struct _net_nfc_client_info_t
-{
- pid_t pid;
- pid_t pgid;
- int socket;
- GIOChannel *channel;
- uint32_t src_id;
- client_state_e state;
- //client_type_e client_type;
- net_nfc_launch_popup_state_e launch_popup_state;
- net_nfc_target_handle_s *target_handle;
-} net_nfc_client_info_t;
-
-typedef void (*net_nfc_server_for_each_client_cb)(net_nfc_client_info_t *client, void *user_param);
-
-void net_nfc_server_deinit_client_context();
-void net_nfc_server_add_client_context(pid_t pid, int socket, GIOChannel *channel, uint32_t src_id, client_state_e state);
-void net_nfc_server_cleanup_client_context(int socket);
-net_nfc_client_info_t *net_nfc_server_get_client_context(int socket);
-int net_nfc_server_get_client_count();
-void net_nfc_server_for_each_client_context(net_nfc_server_for_each_client_cb cb, void *user_param);
-
-bool net_nfc_server_check_client_is_running(int socket);
-client_state_e net_nfc_server_get_client_state(int socket);
-void net_nfc_server_set_client_state(int socket, client_state_e state);
-void net_nfc_server_set_launch_state(int socket, net_nfc_launch_popup_state_e popup_state);
-net_nfc_launch_popup_state_e net_nfc_server_get_client_popup_state(pid_t pid);
-
-#endif /* NET_NFC_SERVER_CONTEXT_H */
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_HANDOVER_H__
+#define __NET_NFC_SERVER_HANDOVER_H__
+
+#include <gio/gio.h>
+#include "net_nfc_gdbus.h"
+#include "net_nfc_typedef_internal.h"
+
+
+typedef struct _HandoverRequestData HandoverRequestData;
+
+struct _HandoverRequestData
+{
+ NetNfcGDbusHandover *handoverobj;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+ gint32 type;
+ data_s *data;
+};
+
+gboolean net_nfc_server_handover_init(GDBusConnection *connection);
+
+void net_nfc_server_handover_deinit(void);
+
+
+#endif //__NET_NFC_SERVER_HANDOVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_HANDOVER_INTERNAL_H__
+#define __NET_NFC_SERVER_HANDOVER_INTERNAL_H__
+
+#include "net_nfc_typedef_internal.h"
+
+typedef void (*net_nfc_server_handover_get_carrier_record_cb)(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_state_e cps,
+ ndef_record_s *carrier,
+ uint32_t aux_data_count,
+ ndef_record_s *aux_data,
+ void *user_param);
+
+typedef void (*net_nfc_server_handover_process_carrier_record_cb)(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param);
+
+
+/* alternative carrier functions */
+net_nfc_error_e net_nfc_server_handover_bt_get_carrier_record(
+ net_nfc_server_handover_get_carrier_record_cb cb, void *user_param);
+
+net_nfc_error_e net_nfc_server_handover_bt_process_carrier_record(
+ ndef_record_s *record, net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_handover_bt_post_process(
+ data_s *data, net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param);
+
+
+
+/* handover server/client functions */
+net_nfc_error_e net_nfc_server_handover_default_server_start(
+ net_nfc_target_handle_s *handle);
+
+net_nfc_error_e net_nfc_server_handover_default_client_start(
+ net_nfc_target_handle_s *handle,
+ void *user_data);
+
+#endif //__NET_NFC_SERVER_HANDOVER_INTERNAL_H__
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef NET_NFC_SERVER_IPC_H
-#define NET_NFC_SERVER_IPC_H
-
-#include <glib-object.h>
-
-#include "net_nfc_typedef_private.h"
-
-#ifdef SECURITY_SERVER
-#define NET_NFC_MANAGER_OBJECT "nfc-manager"
-#endif
-#define NET_NFC_CLIENT_MAX 10
-
-typedef struct net_nfc_server_info_t
-{
- uint32_t server_src_id ;
- GIOChannel *server_channel ;
- int server_sock_fd ;
- uint32_t state;
- net_nfc_current_target_info_s *target_info;
-}net_nfc_server_info_t;
-
-bool net_nfc_server_ipc_initialize();
-void net_nfc_server_ipc_finalize();
-
-bool net_nfc_server_set_server_state(uint32_t state);
-bool net_nfc_server_unset_server_state(uint32_t state);
-uint32_t net_nfc_server_get_server_state();
-
-int net_nfc_server_recv_message_from_client(int client_sock_fd, void* message, int length);
-#ifdef BROADCAST_MESSAGE
-bool net_nfc_broadcast_response_msg(int msg_type, ...);
-bool net_nfc_send_response_msg(int socket, int msg_type, ...);
-#else
-bool net_nfc_send_response_msg(int msg_type, ...);
-#endif
-void net_nfc_server_set_tag_info(void *info);
-bool net_nfc_server_is_target_connected(void *handle);
-net_nfc_current_target_info_s *net_nfc_server_get_tag_info();
-void net_nfc_server_free_current_tag_info();
-
-#endif
-
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_LLCP_H__
+#define __NET_NFC_SERVER_LLCP_H__
+
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+/* define */
+/* Service Name should be followed naming rule. */
+// service access name
+#define SDP_SAN "urn:nfc:sn:sdp"
+#define IP_SAN "urn:nfc:sn:ip"
+#define OBEX_SAN "urn:nfc:sn:obex"
+
+#define SDP_SAP 1 /* service discovery protocol service access point */
+#define IP_SAP 2 /* Internet protocol service access point */
+#define OBEX_SAP 3 /* object exchange service access point */
+
+#define GET_MAJOR_VER(__x) (((__x) >> 4) & 0x0F)
+#define GET_MINOR_VER(__x) ((__x) & 0x0F)
+
+/* default llcp configurations */
+#define NET_NFC_LLCP_MIU 128
+#define NET_NFC_LLCP_WKS 1
+#define NET_NFC_LLCP_LTO 10
+#define NET_NFC_LLCP_OPT 0
+
+typedef enum
+{
+ NET_NFC_LLCP_IDLE = 0,
+ NET_NFC_LLCP_STEP_01 = 0xFFFF,
+ NET_NFC_LLCP_STEP_02,
+ NET_NFC_LLCP_STEP_03,
+ NET_NFC_LLCP_STEP_04,
+ NET_NFC_LLCP_STEP_05,
+ NET_NFC_LLCP_STEP_06,
+ NET_NFC_LLCP_STEP_07,
+ NET_NFC_LLCP_STEP_08,
+ NET_NFC_LLCP_STEP_09,
+ NET_NFC_LLCP_STEP_10,
+ NET_NFC_LLCP_STEP_11,
+ NET_NFC_LLCP_STEP_12,
+ NET_NFC_LLCP_STEP_13,
+ NET_NFC_LLCP_STEP_14,
+ NET_NFC_LLCP_STEP_15,
+ NET_NFC_LLCP_STEP_16,
+ NET_NFC_LLCP_STEP_17,
+ NET_NFC_LLCP_STEP_18,
+ NET_NFC_LLCP_STEP_19,
+ NET_NFC_LLCP_STEP_20,
+ NET_NFC_LLCP_STEP_RETURN,
+ NET_NFC_STATE_SOCKET_ERROR,
+ NET_NFC_STATE_ERROR,
+} net_nfc_state_e;
+
+typedef void (*net_nfc_server_llcp_callback) (net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+typedef void (*net_nfc_server_llcp_activate_cb)(
+ int event,
+ net_nfc_target_handle_s *handle,
+ uint32_t sap,
+ const char *san,
+ void *user_param);
+
+gboolean net_nfc_server_llcp_init(GDBusConnection *connection);
+
+void net_nfc_server_llcp_deinit(void);
+
+/* server side */
+void net_nfc_server_llcp_deactivated(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_listen(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_socket_error(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_socket_accepted_error(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_send(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_receive(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_receive_from(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_connect(net_nfc_request_msg_t *req_msg);
+
+void net_nfc_server_llcp_disconnect(net_nfc_request_msg_t *req_msg);
+
+net_nfc_error_e net_nfc_server_llcp_set_config(
+ net_nfc_llcp_config_info_s *config);
+
+guint16 net_nfc_server_llcp_get_miu(void);
+
+guint16 net_nfc_server_llcp_get_wks(void);
+
+guint8 net_nfc_server_llcp_get_lto(void);
+
+guint8 net_nfc_server_llcp_get_option(void);
+
+void net_nfc_server_llcp_target_detected(void *info);
+
+net_nfc_error_e net_nfc_server_llcp_simple_server(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_llcp_callback callback,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_simple_client(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_llcp_callback callback,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_simple_accept(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_simple_send(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ net_nfc_server_llcp_callback callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_simple_receive(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_server_llcp_callback callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_llcp_register_service(const char *id,
+ sap_t sap, const char *san, net_nfc_server_llcp_activate_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_llcp_unregister_service(const char *id,
+ sap_t sap, const char *san);
+
+net_nfc_error_e net_nfc_server_llcp_unregister_services(const char *id);
+
+net_nfc_error_e net_nfc_server_llcp_unregister_all();
+
+net_nfc_error_e net_nfc_server_llcp_start_registered_services(
+ net_nfc_target_handle_s *handle);
+
+#endif //__NET_NFC_SERVER_LLCP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_MANAGER_H__
+#define __NET_NFC_SERVER_MANAGER_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_manager_init(GDBusConnection *connection);
+
+void net_nfc_server_manager_deinit(void);
+
+void net_nfc_server_manager_set_active(gboolean is_active);
+
+bool net_nfc_server_manager_get_active();
+
+#endif //__NET_NFC_SERVER_MANAGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_NDEF_H__
+#define __NET_NFC_SERVER_NDEF_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_ndef_init(GDBusConnection *connection);
+
+void net_nfc_server_ndef_deinit(void);
+
+#endif //__NET_NFC_SERVER_NDEF_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_P2P_H__
+#define __NET_NFC_SERVER_P2P_H__
+
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+gboolean net_nfc_server_p2p_init(GDBusConnection *connection);
+
+void net_nfc_server_p2p_deinit(void);
+
+/* server side */
+void net_nfc_server_p2p_detached(void);
+
+void net_nfc_server_p2p_discovered(net_nfc_target_handle_h handle);
+
+void net_nfc_server_p2p_received(data_h user_data);
+
+void net_nfc_server_p2p_data_sent(net_nfc_error_e result, gpointer user_data);
+
+#endif //__NET_NFC_SERVER_P2P_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_PROCESS_HANDOVER_H__
+#define __NET_NFC_SERVER_PROCESS_HANDOVER_H__
+
+#include "net_nfc_typedef_internal.h"
+
+net_nfc_error_e net_nfc_server_handover_default_server_start(
+ net_nfc_target_handle_s *handle);
+
+net_nfc_error_e net_nfc_server_handover_default_client_start(
+ net_nfc_target_handle_s *handle,
+ void *user_data);
+
+net_nfc_error_e net_nfc_server_handover_default_server_register();
+
+net_nfc_error_e net_nfc_server_handover_default_server_unregister();
+
+#endif //__NET_NFC_SERVER_PROCESS_HANDOVER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_PROCESS_NPP_H__
+#define __NET_NFC_SERVER_PROCESS_NPP_H__
+
+#include <glib.h>
+
+#include "net_nfc_typedef.h"
+#include "net_nfc_typedef_internal.h"
+
+typedef void (*net_nfc_server_npp_callback) (net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_npp_server(net_nfc_target_handle_s *handle,
+ char *san,
+ sap_t sap,
+ net_nfc_server_npp_callback callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_npp_client(net_nfc_target_handle_s *handle,
+ char *san,
+ sap_t sap,
+ data_s *data,
+ net_nfc_server_npp_callback callback,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_npp_default_server_start(
+ net_nfc_target_handle_s *handle);
+
+net_nfc_error_e net_nfc_server_npp_default_client_start(
+ net_nfc_target_handle_s *handle,
+ data_s *data,
+ int client,
+ gpointer user_data);
+
+net_nfc_error_e net_nfc_server_npp_default_server_register();
+
+net_nfc_error_e net_nfc_server_npp_default_server_unregister();
+
+#endif //__NET_NFC_SERVER_PROCESS_NPP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_PROCESS_SNEP_H__
+#define __NET_NFC_SERVER_PROCESS_SNEP_H__
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_typedef_internal.h"
+
+#define SNEP_SAN "urn:nfc:sn:snep"
+#define SNEP_SAP 4
+
+typedef enum
+{
+ SNEP_REQ_CONTINUE = 0x00,
+ SNEP_REQ_GET = 0x01,
+ SNEP_REQ_PUT = 0x02,
+ SNEP_REQ_REJECT = 0x7F,
+ SNEP_RESP_CONT = 0x80,
+ SNEP_RESP_SUCCESS = 0x81,
+ SNEP_RESP_NOT_FOUND = 0xC0,
+ SNEP_RESP_EXCESS_DATA = 0xC1,
+ SNEP_RESP_BAD_REQ = 0xC2,
+ SNEP_RESP_NOT_IMPLEMENT = 0xE0,
+ SNEP_RESP_UNSUPPORTED_VER = 0xE1,
+ SNEP_RESP_REJECT = 0xFF,
+} snep_command_field_e;
+
+typedef bool (*net_nfc_server_snep_listen_cb)(net_nfc_snep_handle_h handle,
+ uint32_t type,
+ uint32_t max_len,
+ data_s *data,
+ void *user_param);
+
+typedef net_nfc_error_e (*net_nfc_server_snep_cb)(net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_snep_server(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_snep_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_snep_client(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_snep_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_snep_server_send_get_response(
+ net_nfc_snep_handle_h snep_handle,
+ data_s *data);
+
+net_nfc_error_e net_nfc_server_snep_client_request(
+ net_nfc_snep_handle_h snep,
+ uint8_t type,
+ data_s *data,
+ net_nfc_server_snep_cb cb,
+ void *user_param);
+
+net_nfc_error_e net_nfc_server_snep_default_server_start(
+ net_nfc_target_handle_s *handle);
+
+net_nfc_error_e net_nfc_server_snep_default_client_start(
+ net_nfc_target_handle_s *handle,
+ int type,
+ data_s *data,
+ int client,
+ void *user_param);
+
+net_nfc_error_e
+net_nfc_server_snep_default_server_register_get_response_cb(
+ net_nfc_server_snep_listen_cb cb,
+ void *user_param);
+
+net_nfc_error_e
+net_nfc_server_snep_default_server_unregister_get_response_cb(
+ net_nfc_server_snep_listen_cb cb);
+
+net_nfc_error_e
+net_nfc_server_snep_default_server_send_get_response(
+ net_nfc_snep_handle_h snep_handle,
+ data_s *data);
+
+net_nfc_error_e net_nfc_server_snep_default_server_register();
+
+net_nfc_error_e net_nfc_server_snep_default_server_unregister();
+
+net_nfc_error_e net_nfc_server_snep_parse_get_request(data_s *request,
+ size_t *max_len, data_s *message);
+
+#endif //__NET_NFC_SERVER_PROCESS_SNEP_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_SE_H__
+#define __NET_NFC_SERVER_SE_H__
+
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+
+/***************************************************************/
+
+uint8_t net_nfc_server_se_get_se_type();
+
+uint8_t net_nfc_server_se_get_se_mode();
+
+net_nfc_error_e net_nfc_server_se_change_se(uint8_t type);
+
+/***************************************************************/
+
+gboolean net_nfc_server_se_init(GDBusConnection *connection);
+
+void net_nfc_server_se_deinit(void);
+
+void net_nfc_server_se_detected(void *info);
+
+void net_nfc_server_se_transaction_received(void *info);
+
+#endif //__NET_NFC_SERVER_SE_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_SNEP_H__
+#define __NET_NFC_SERVER_SNEP_H__
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_typedef_internal.h"
+
+gboolean net_nfc_server_snep_init(GDBusConnection *connection);
+
+void net_nfc_server_snep_deinit(void);
+
+#endif //__NET_NFC_SERVER_SNEP_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_SYSTEM_HANDLER_H__
+#define __NET_NFC_SERVER_SYSTEM_HANDLER_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_system_handler_init(GDBusConnection *connection);
+
+void net_nfc_server_system_handler_deinit(void);
+
+#endif //__NET_NFC_SERVER_SYSTEM_HANDLER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_TAG_H__
+#define __NET_NFC_SERVER_TAG_H__
+
+#include <gio/gio.h>
+
+#include "net_nfc_typedef_internal.h"
+
+gboolean net_nfc_server_tag_init(GDBusConnection *connection);
+
+void net_nfc_server_tag_deinit(void);
+
+void net_nfc_server_set_target_info(void *info);
+
+net_nfc_current_target_info_s *net_nfc_server_get_target_info(void);
+
+gboolean net_nfc_server_target_connected(net_nfc_target_handle_s *handle);
+
+void net_nfc_server_free_target_info(void);
+
+void net_nfc_server_tag_target_detected(void *info);
+
+#endif //__NET_NFC_SERVER_TAG_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_TEST_H__
+#define __NET_NFC_SERVER_TEST_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_test_init(GDBusConnection *connection);
+
+void net_nfc_server_test_deinit(void);
+
+#endif //__NET_NFC_SERVER_TEST_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_TRANSCEIVE_H__
+#define __NET_NFC_SERVER_TRANSCEIVE_H__
+
+#include <gio/gio.h>
+
+gboolean net_nfc_server_transceive_init(GDBusConnection *connection);
+
+void net_nfc_server_transceive_deinit(void);
+
+#endif //__NET_NFC_SERVER_TRANSCEIVE_H__
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_SERVER_VCONF_H__
+#define __NET_NFC_SERVER_VCONF_H__
+
+void net_nfc_server_vconf_init(void);
+
+void net_nfc_server_vconf_deinit(void);
+
+#endif //__NET_NFC_SERVER_VCONF_H__
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_SERVICE_LLCP_HANDOVER_PRVIATE_H_
-#define NET_NFC_SERVICE_LLCP_HANDOVER_PRVIATE_H_
-
-#include "net_nfc_typedef_private.h"
-
-typedef struct _carrier_record
-{
- ndef_record_s *record;
- net_nfc_conn_handover_carrier_type_e type;
- net_nfc_conn_handover_carrier_state_e state;
-} carrier_record_s;
-
-net_nfc_error_e net_nfc_service_llcp_handover_send_request_msg(net_nfc_request_connection_handover_t *msg);
-
-bool net_nfc_service_llcp_connection_handover_selector(net_nfc_llcp_state_t *state, net_nfc_error_e *result);
-bool net_nfc_service_llcp_connection_handover_requester(net_nfc_llcp_state_t *state, net_nfc_error_e *result);
-
-#endif /* NET_NFC_SERVICE_LLCP_HANDOVER_PRVIATE_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef NET_NFC_SERVICE_LLCP_PRIVATE_H
-#define NET_NFC_SERVICE_LLCP_PRIVATE_H
-
-#include "net_nfc_typedef_private.h"
-
-/* define */
-/* Service Name should be followed naming rule. */
-// service access name
-
-#define SDP_SAN "urn:nfc:sn:sdp"
-#define IP_SAN "urn:nfc:sn:ip"
-#define SNEP_SAN "urn:nfc:sn:snep"
-#define OBEX_SAN "urn:nfc:sn:obex"
-
-#define CONN_HANDOVER_SAN "urn:nfc:sn:handover"
-
-#define NPP_SAN "com.android.npp"
-#define NPP_SAP 0x10
-
-#define SDP_SAP 1 /* service discovery protocol service access point */
-#define IP_SAP 2 /* Internet protocol service access point */
-#define OBEX_SAP 3 /* ojbect exchange service access point */
-#define SNEP_SAP 4 /* simple ndef exchange protocol service access point */
-
-#define CONN_HANDOVER_SAP 5 /* connection handover service access point */
-
-#define SNEP_MAJOR_VER 1
-#define SNEP_MINOR_VER 0
-
-#define NPP_MAJOR_VER 0
-#define NPP_MINOR_VER 1
-
-#define NPP_NDEF_ENTRY 0x00000001
-
-#define NPP_ACTION_CODE 0x01
-
-#define SNEP_MAX_BUFFER 128 /* simple NDEF exchange protocol */
-#define CH_MAX_BUFFER 128 /* connection handover */
-
-typedef enum{
- NPP_REQ_CONTINUE = 0x00,
- NPP_REQ_REJECT,
- NPP_RESP_CONT,
- NPP_RESP_SUCCESS,
- NPP_RESP_NOT_FOUND,
- NPP_RESP_EXCESS_DATA,
- NPP_RESP_BAD_REQ,
- NPP_RESP_NOT_IMPLEMEN,
- NPP_RESP_UNSUPPORTED_VER,
- NPP_RESP_REJECT,
-}npp_command_field_e;
-
-typedef enum{
- SNEP_REQ_CONTINUE = 0x00,
- SNEP_REQ_GET = 0x01,
- SNEP_REQ_PUT = 0x02,
- SNEP_REQ_REJECT = 0x7F,
- SNEP_RESP_CONT = 0x80,
- SNEP_RESP_SUCCESS = 0x81,
- SNEP_RESP_NOT_FOUND = 0xC0,
- SNEP_RESP_EXCESS_DATA = 0xC1,
- SNEP_RESP_BAD_REQ = 0xC2,
- SNEP_RESP_NOT_IMPLEMENT = 0xE0,
- SNEP_RESP_UNSUPPORTED_VER = 0xE1,
- SNEP_RESP_REJECT = 0xFF,
-}snep_command_field_e;
-
-/* static variable */
-
-typedef enum {
- NET_NFC_STATE_EXCHANGER_SERVER = 0x00,
- NET_NFC_STATE_EXCHANGER_SERVER_NPP,
-
- NET_NFC_STATE_EXCHANGER_CLIENT,
- NET_NFC_STATE_CONN_HANDOVER_REQUEST,
- NET_NFC_STATE_CONN_HANDOVER_SELECT,
-} llcp_state_e;
-
-typedef enum {
- NET_NFC_LLCP_STEP_01 = 0xFFFF,
- NET_NFC_LLCP_STEP_02,
- NET_NFC_LLCP_STEP_03,
- NET_NFC_LLCP_STEP_04,
- NET_NFC_LLCP_STEP_05,
- NET_NFC_LLCP_STEP_06,
- NET_NFC_LLCP_STEP_07,
- NET_NFC_LLCP_STEP_08,
- NET_NFC_LLCP_STEP_09,
- NET_NFC_LLCP_STEP_10,
- NET_NFC_LLCP_STEP_11,
- NET_NFC_LLCP_STEP_12,
- NET_NFC_LLCP_STEP_13,
- NET_NFC_LLCP_STEP_14,
- NET_NFC_LLCP_STEP_15,
- NET_NFC_LLCP_STEP_16,
- NET_NFC_LLCP_STEP_17,
- NET_NFC_LLCP_STEP_18,
- NET_NFC_LLCP_STEP_19,
- NET_NFC_LLCP_STEP_20,
- NET_NFC_LLCP_STEP_RETURN,
- NET_NFC_STATE_SOCKET_ERROR,
- NET_NFC_STATE_ERROR,
-} net_nfc_state_e;
-
-typedef struct _net_nfc_llcp_state_t{
- int client_fd;
- unsigned int step;
- unsigned int fragment_offset;
- llcp_state_e state;
- net_nfc_llcp_socket_t socket;
- uint16_t max_capability;
- net_nfc_target_handle_s * handle;
- net_nfc_error_e prev_result;
- net_nfc_llcp_socket_t incomming_socket;
- ndef_message_s *requester;
- ndef_message_s *selector;
- bool low_power;
- void * user_data;
- void * payload;
-
- llcp_app_protocol_e type_app_protocol;
- net_nfc_conn_handover_carrier_type_e type;
-
-} net_nfc_llcp_state_t;
-
-
-typedef struct _net_nfc_llcp_npp_t{
- uint8_t npp_version;
- uint32_t npp_ndef_entry;
- uint8_t npp_action_code;
- uint32_t npp_ndef_length;
-} __attribute__((packed))net_nfc_llcp_npp_t;
-
-#define NET_NFC_COMMON_HANDOVER_CONTEXT unsigned int step;\
- net_nfc_llcp_state_t *llcp_state;\
- void *user_data;\
- net_nfc_error_e result;\
- net_nfc_conn_handover_carrier_type_e request_type;\
- void *data;\
- bool is_requester;
-
-typedef struct _net_nfc_handover_context_t
-{
- NET_NFC_COMMON_HANDOVER_CONTEXT;
-}
-net_nfc_handover_context_t;
-
-typedef struct _net_nfc_handover_create_config_context_t
-{
- NET_NFC_COMMON_HANDOVER_CONTEXT;
-
- net_nfc_conn_handover_carrier_type_e current_type;
- ndef_message_s *ndef_message;
- ndef_message_s *requester; /* for low power selector */
- bool is_low_power;
-}
-net_nfc_handover_create_config_context_t;
-
-typedef struct _net_nfc_handover_process_config_context_t
-{
- NET_NFC_COMMON_HANDOVER_CONTEXT;
-
- net_nfc_carrier_config_s *config;
-}
-net_nfc_handover_process_config_context_t;
-
-bool net_nfc_service_llcp_process_accept(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_terminate_connection(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_disconnect_target(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_socket_error(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_accepted_socket_error(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_send_to_socket(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_send_socket(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_receive_socket(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_receive_from_socket(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_connect_socket(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_connect_sap_socket(net_nfc_request_msg_t* msg);
-bool net_nfc_service_llcp_process_disconnect_socket(net_nfc_request_msg_t* msg);
-net_nfc_error_e net_nfc_service_send_exchanger_msg(net_nfc_request_p2p_send_t* msg);
-bool net_nfc_service_llcp_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result);
-
-void net_nfc_service_llcp_remove_state (net_nfc_llcp_state_t * state);
-void net_nfc_service_llcp_add_state (net_nfc_llcp_state_t * state);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_SERVICE_PRIVATE_H
-#define NET_NFC_SERVICE_PRIVATE_H
-
-#include "net_nfc_typedef_private.h"
-
-bool net_nfc_service_slave_mode_target_detected(net_nfc_request_msg_t* msg);
-#ifndef BROADCAST_MESSAGE
-bool net_nfc_service_standalone_mode_target_detected(net_nfc_request_msg_t* msg);
-#endif
-bool net_nfc_service_termination (net_nfc_request_msg_t* msg);
-
-void net_nfc_service_target_detected_cb(void* info, void* user_context);
-void net_nfc_service_se_transaction_cb(void* info, void* user_context);
-void net_nfc_service_llcp_event_cb(void* info, void* user_context);
-
-void net_nfc_service_msg_processing(data_s* data);
-
-void net_nfc_service_is_tag_connected(net_nfc_request_msg_t *msg);
-void net_nfc_service_get_current_tag_info(net_nfc_request_msg_t *msg);
-void net_nfc_service_get_current_target_handle(net_nfc_request_msg_t *msg);
-void net_nfc_service_init(net_nfc_request_msg_t *msg);
-void net_nfc_service_deinit(net_nfc_request_msg_t *msg);
-
-void net_nfc_service_restart_polling(net_nfc_request_msg_t *msg);
-void net_nfc_service_get_server_state(net_nfc_request_msg_t *msg);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef NET_NFC_SERVICE_SE_PRIVATE_H
-#define NET_NFC_SERVICE_SE_PRIVATE_H
-
-#include "net_nfc_typedef_private.h"
-
-typedef struct _se_setting_t
-{
- net_nfc_target_handle_s *current_ese_handle;
- void *open_request_trans_param;
- uint8_t type;
- uint8_t mode;
-}
-net_nfc_se_setting_t;
-
-net_nfc_se_setting_t *net_nfc_service_se_get_se_setting();
-net_nfc_target_handle_s *net_nfc_service_se_get_current_ese_handle();
-void net_nfc_service_se_set_current_ese_handle(net_nfc_target_handle_s *handle);
-uint8_t net_nfc_service_se_get_se_type();
-void net_nfc_service_se_set_se_type(uint8_t type);
-uint8_t net_nfc_service_se_get_se_mode();
-void net_nfc_service_se_set_se_mode(uint8_t mode);
-
-net_nfc_error_e net_nfc_service_se_change_se(uint8_t type);
-
-void net_nfc_service_se_detected(net_nfc_request_msg_t *req_msg);
-net_nfc_error_e net_nfc_service_se_close_ese();
-
-/* TAPI SIM API */
-
-bool net_nfc_service_tapi_init(void);
-void net_nfc_service_tapi_deinit(void);
-bool net_nfc_service_transfer_apdu(int client_fd, data_s *apdu, void *trans_param);
-bool net_nfc_service_request_atr(int client_fd, void *trans_param);
-bool net_nfc_service_se_transaction_receive(net_nfc_request_msg_t* msg);
-void net_nfc_service_se_send_apdu(net_nfc_request_msg_t *msg);
-void net_nfc_service_se_get_atr(net_nfc_request_msg_t *msg);
-void net_nfc_service_se_close_se(net_nfc_request_msg_t *msg);
-void net_nfc_service_se_open_se(net_nfc_request_msg_t *msg);
-void net_nfc_service_se_set_se(net_nfc_request_msg_t *msg);
-void net_nfc_service_se_get_se(net_nfc_request_msg_t *msg);
-void net_nfc_service_se_cleanup();
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_SERVICE_TAG_PRIVATE_H
-#define NET_NFC_SERVICE_TAG_PRIVATE_H
-
-#include "net_nfc_typedef_private.h"
-
-data_s* net_nfc_service_tag_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result);
-void net_nfc_service_clean_tag_context(net_nfc_request_target_detected_t* stand_alone, net_nfc_error_e result);
-void net_nfc_service_watch_dog(net_nfc_request_msg_t* req_msg);
-
-void net_nfc_service_tag_make_readonly(net_nfc_request_msg_t *msg);
-void net_nfc_service_tag_read_ndef(net_nfc_request_msg_t *msg);
-void net_nfc_service_tag_write_ndef(net_nfc_request_msg_t *msg);
-void net_nfc_service_tag_format_ndef(net_nfc_request_msg_t *msg);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef NET_NFC_SERVICE_VCONF_H
-#define NET_NFC_SERVICE_VCONF_H
-
-void net_nfc_service_vconf_register_notify_listener();
-void net_nfc_service_vconf_unregister_notify_listener();
-bool _net_nfc_check_pprom_is_completed ();
-void _net_nfc_set_pprom_is_completed ();
-
-
-#endif
#include "Ecore_X.h"
#include "net_nfc_typedef.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
#include "net_nfc_util_defines.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_ndef_message.h"
#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_manager_util_private.h"
-#include "net_nfc_app_util_private.h"
-#include "net_nfc_server_context_private.h"
+#include "net_nfc_manager_util_internal.h"
+#include "net_nfc_app_util_internal.h"
+#include "net_nfc_server_context_internal.h"
+#include "net_nfc_server_se.h"
//#include "syspopup_caller.h"
-#define OSP_K_COND "__OSP_COND_NAME__"
-#define OSP_K_COND_TYPE "nfc"
-#define OSP_K_LAUNCH_TYPE "__OSP_LAUNCH_TYPE__"
+#define OSP_K_COND "__OSP_COND_NAME__"
+#define OSP_K_COND_TYPE "nfc"
+#define OSP_K_LAUNCH_TYPE "__OSP_LAUNCH_TYPE__"
static bool _net_nfc_app_util_get_operation_from_record(ndef_record_s *record, char *operation, size_t length);
static bool _net_nfc_app_util_get_mime_from_record(ndef_record_s *record, char *mime, size_t length);
#endif
static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *data, size_t length);
-static const char *sbeam_mime_type[] =
-{
- "text/DirectShareGallery",
- "text/DirectShareMusic",
- "text/DirectShareVideos",
- "text/DirectShareFile",
- "text/DirectSharePolarisViewer",
- "text/DirectSharePolarisEditor",
- "text/DirectShareDefault",
- "text/DirectShareError",
- NULL
-};
-
static const char osp_launch_type_condition[] = "condition";
net_nfc_error_e net_nfc_app_util_process_ndef(data_s *data)
char uri[2048] = { 0, };
#endif
int ret = 0;
- int disable = 0;
if (data == NULL || data->buffer == NULL || data->length == 0)
{
int result;
char command[1024];
- DEBUG_SERVER_MSG("path doesn't exist, do mkdir : %s", file_name);
+ SECURE_LOGD("path doesn't exist, do mkdir : %s", file_name);
snprintf(command, sizeof(command), "mkdir -p -m 755 %s", file_name);
/* create file */
snprintf(file_name, sizeof(file_name), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH,
NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME);
- DEBUG_SERVER_MSG("file path : %s", file_name);
+ SECURE_LOGD("file path : %s", file_name);
unlink(file_name);
rmdir(src_path);
}
-static bool __check_is_sbeam_record(ndef_record_s *record)
-{
- data_s *type_s = &record->type_s;
- int index = 0;
-
- if (type_s->buffer == NULL || type_s->length == 0)
- {
- return FALSE;
- }
-
- DEBUG_SERVER_MSG("mime : %s", type_s->buffer);
-
- while (sbeam_mime_type[index] != NULL)
- {
- if (strncasecmp((char *)type_s->buffer, sbeam_mime_type[index],
- MIN(type_s->length, strlen(sbeam_mime_type[index]))) == 0)
- {
- return TRUE;
- }
- index++;
- }
-
- return FALSE;
-}
-
static void _to_lower_utf_8(char *str)
{
while (*str != 0)
break;
case NET_NFC_RECORD_MIME_TYPE :
- {
- if (__check_is_sbeam_record(record))
- op_text = "http://tizen.org/appcontrol/operation/nfc_sbeam_receive";
- else
- op_text = "http://tizen.org/appcontrol/operation/nfc/mime";
- }
- break;
+ op_text = "http://tizen.org/appcontrol/operation/nfc/mime";
+ break;
case NET_NFC_RECORD_URI : /* Absolute URI */
op_text = "http://tizen.org/appcontrol/operation/nfc/uri";
{
DEBUG_SERVER_MSG("operation : %s", operation);
appsvc_set_operation(bd, operation);
- }
+ }
if (uri != NULL && strlen(uri) > 0)
{
int net_nfc_app_util_launch_se_transaction_app(uint8_t *aid, uint32_t aid_len, uint8_t *param, uint32_t param_len)
{
- int result;
bundle *bd = NULL;
/* launch */
appsvc_add_data(bd, "data", param_string);
}
- result = appsvc_run_service(bd, 0, NULL, NULL);
-
+ appsvc_run_service(bd, 0, NULL, NULL);
bundle_free(bd);
- return result;
+ return 0;
}
int net_nfc_app_util_encode_base64(uint8_t *buffer, uint32_t buf_len, char *result, uint32_t max_result)
focus_app_pid = _net_nfc_app_util_get_focus_app_pid();
- popup_state = net_nfc_server_get_client_popup_state(focus_app_pid);
+ popup_state = net_nfc_server_gdbus_get_client_popup_state(focus_app_pid);
if(popup_state == NET_NFC_NO_LAUNCH_APP_SELECT)
result = true;
return result;
}
-
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#include <linux/limits.h>
#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <string.h>
+#include <errno.h>
#include <pmapi.h>/*for pm lock*/
#include "net_nfc_oem_controller.h"
-#include "net_nfc_controller_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_server_dispatcher_private.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_server_tag.h"
+
+#define NET_NFC_OEM_LIBRARY_PATH "/usr/lib/libnfc-plugin.so"
+#define NET_NFC_DEFAULT_PLUGIN "libnfc-plugin.so"
-#define NET_NFC_OEM_LIBRARY_PATH LIBPATH "/libnfc-plugin.so"
static net_nfc_oem_interface_s g_interface;
-void *net_nfc_controller_onload()
+static void *net_nfc_controller_load_file(const char *dir_path,
+ const char *filename)
{
- void* handle = NULL;
+ void *handle = NULL;
+ char path[PATH_MAX] = { '\0' };
+ struct stat st;
+
+ net_nfc_error_e result;
+
bool (*onload)(net_nfc_oem_interface_s *interfaces);
- FILE *fp;
- char cpuinfo_buffer[1024] = { 0, };
- size_t bytes_read;
- char *match_revision;
- int revision;
- char *token;
- char *token_cpuinfo[10];
- int i = 0;
- const char *library_path;
+ snprintf(path, PATH_MAX, "%s/%s", dir_path, filename);
+ DEBUG_SERVER_MSG("path : %s", path);
- fp = fopen("/proc/cpuinfo", "r");
- bytes_read = fread(cpuinfo_buffer, 1, sizeof(cpuinfo_buffer) - 1, fp);/* Read the cpuinfo to bytes_read */
- fclose(fp);
+ if (stat(path, &st) == -1) {
+ DEBUG_ERR_MSG("stat failed : file not found");
+ goto ERROR;
+ }
- match_revision = strstr(cpuinfo_buffer, "Hardware");
- if (match_revision != NULL)
- {
- token = strtok(match_revision, " :\n");
+ if (S_ISREG(st.st_mode) == 0) {
+ DEBUG_ERR_MSG("S_ISREG(st.st_mode) == 0");
+ goto ERROR;
+ }
- while (token != NULL && i < 5)
- {
- i++;
- DEBUG_SERVER_MSG("token = %s", token);
+ handle = dlopen(path, RTLD_LAZY);
+ if (handle == NULL) {
+ char buffer[1024];
+ DEBUG_ERR_MSG("dlopen failed, [%d] : %s",
+ errno, strerror_r(errno, buffer, sizeof(buffer)));
+ goto ERROR;
+ }
- token = strtok(NULL, " :\n");
+ onload = dlsym(handle, "onload");
+ if (onload == NULL) {
+ char buffer[1024];
+ DEBUG_ERR_MSG("dlsym failed, [%d] : %s",
+ errno, strerror_r(errno, buffer, sizeof(buffer)));
+ goto ERROR;
+ }
- token_cpuinfo[i] = token;
- DEBUG_SERVER_MSG("temp[%d]'s value = %s", i, token_cpuinfo[i]);
- }
+ memset(&g_interface, 0, sizeof(g_interface));
+ if (onload(&g_interface) == false) {
+ DEBUG_ERR_MSG("onload failed");
+ goto ERROR;
+ }
- revision = strtol(token_cpuinfo[3], 0, 16);
- DEBUG_SERVER_MSG("revision = %d", revision);
+ if (net_nfc_controller_support_nfc(&result) == false) {
+ DEBUG_ERR_MSG("net_nfc_controller_support_nfc failed, [%d]",
+ result);
+ goto ERROR;
+ }
- if ((!(strncmp(token_cpuinfo[1], "SLP_PQ", 6)) && (revision >= 7))) //|| !(strncmp(token_cpuinfo[1] , "REDWOOD" , 7)))
- {
- DEBUG_SERVER_MSG("It's SLP_PQ && Revision 7!! || REDWOOD revC.");
- library_path = LIBPATH "/libnfc-plugin-65nxp.so";
+ return handle;
- }
- else if (!(strncmp(token_cpuinfo[1], "REDWOOD", 7)))
- {
- DEBUG_SERVER_MSG("It's REDWOOD revC.");
- library_path = LIBPATH "/libnfc-plugin-lsi.so";
- }
- else
- {
- DEBUG_SERVER_MSG("It's NOT!!!! SLP_PQ && Revision 7!!");
- library_path = LIBPATH "/libnfc-plugin.so";
- }
+ERROR :
+ if (handle != NULL) {
+ dlclose(handle);
}
- else
+
+ return NULL;
+}
+
+void *net_nfc_controller_onload()
+{
+ DIR *dirp;
+ struct dirent *dir;
+
+ void *handle = NULL;
+
+ dirp = opendir(NFC_MANAGER_MODULEDIR);
+ if (dirp == NULL)
{
- DEBUG_SERVER_MSG("It doesn't have Hardware info!!");
- library_path = LIBPATH "/libnfc-plugin.so";
+ DEBUG_ERR_MSG("Can not open directory %s",
+ NFC_MANAGER_MODULEDIR);
+ return NULL;
}
- if ((handle = dlopen(library_path/*NET_NFC_OEM_LIBRARY_PATH*/, RTLD_LAZY)) != NULL)
+ while ((dir = readdir(dirp)))
{
- if ((onload = dlsym(handle, "onload")) != NULL)
+ if ((strcmp(dir->d_name, ".") == 0) ||
+ (strcmp(dir->d_name, "..") == 0))
{
- if (onload(&g_interface) == true)
- {
- DEBUG_SERVER_MSG("success to load library");
- return handle;
- }
- else
- {
- DEBUG_ERR_MSG("failed to load library");
- }
+ continue;
}
- else
+
+ /* check ".so" suffix */
+ if (strcmp(dir->d_name + (strlen(dir->d_name) - strlen(".so")),
+ ".so") != 0)
+ continue;
+
+ /* check default plugin later */
+ if (strcmp(dir->d_name, NET_NFC_DEFAULT_PLUGIN) == 0)
+ continue;
+
+ handle = net_nfc_controller_load_file(NFC_MANAGER_MODULEDIR,
+ dir->d_name);
+ if (handle)
{
- DEBUG_ERR_MSG("can not find symbol onload");
+ SECURE_LOGD("Successfully loaded : %s",
+ dir->d_name);
+ closedir(dirp);
+ return handle;
}
+ }
- dlclose(handle);
- handle = NULL;
+ closedir(dirp);
+
+ /* load default plugin */
+ handle = net_nfc_controller_load_file(NFC_MANAGER_MODULEDIR,
+ NET_NFC_DEFAULT_PLUGIN);
+
+ if (handle)
+ {
+ DEBUG_SERVER_MSG("loaded default plugin : %s",
+ NET_NFC_DEFAULT_PLUGIN);
+ return handle;
}
else
{
- DEBUG_ERR_MSG("dlopen is failed");
+ DEBUG_ERR_MSG("can not load default plugin : %s",
+ NET_NFC_DEFAULT_PLUGIN);
+ return NULL;
}
-
- return handle;
}
-bool net_nfc_controller_unload(void* handle)
+bool net_nfc_controller_unload(void *handle)
{
memset(&g_interface, 0x00, sizeof(net_nfc_oem_interface_s));
return true;
}
-bool net_nfc_controller_init(net_nfc_error_e* result)
+bool net_nfc_controller_init(net_nfc_error_e *result)
{
if (g_interface.init != NULL)
{
}
bool net_nfc_controller_register_listener(target_detection_listener_cb target_detection_listener,
- se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e* result)
+ se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e *result)
{
if (g_interface.register_listener != NULL)
{
}
}
-bool net_nfc_controller_check_firmware_version(net_nfc_error_e* result)
+bool net_nfc_controller_check_firmware_version(net_nfc_error_e *result)
{
if (g_interface.check_firmware_version != NULL)
{
}
}
-bool net_nfc_controller_update_firmware(net_nfc_error_e* result)
+bool net_nfc_controller_update_firmware(net_nfc_error_e *result)
{
if (g_interface.update_firmeware != NULL)
{
}
}
-bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s* stack_info, net_nfc_error_e* result)
+bool net_nfc_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result)
{
if (g_interface.get_stack_information != NULL)
{
}
}
-bool net_nfc_controller_confiure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e* result)
+bool net_nfc_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result)
{
if (g_interface.configure_discovery != NULL)
{
}
}
-bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s* list, int* count, net_nfc_error_e* result)
+bool net_nfc_controller_get_secure_element_list(net_nfc_secure_element_info_s *list, int *count, net_nfc_error_e *result)
{
if (g_interface.get_secure_element_list != NULL)
{
}
}
-bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e* result)
+bool net_nfc_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e *result)
{
if (g_interface.set_secure_element_mode != NULL)
{
}
}
-bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s* handle, net_nfc_error_e* result)
+bool net_nfc_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
{
if (g_interface.check_presence != NULL)
{
}
}
-bool net_nfc_controller_connect(net_nfc_target_handle_s* handle, net_nfc_error_e* result)
+bool net_nfc_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
{
int ret_val = 0;
}
}
-bool net_nfc_controller_disconnect(net_nfc_target_handle_s* handle, net_nfc_error_e* result)
+bool net_nfc_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
{
int ret_val = 0;
if (g_interface.disconnect != NULL)
{
- net_nfc_server_free_current_tag_info();
+ net_nfc_server_free_target_info();
return g_interface.disconnect(handle, result);
}
}
}
-bool net_nfc_controller_check_ndef(net_nfc_target_handle_s* handle, uint8_t *ndef_card_state, int* max_data_size, int* real_data_size, net_nfc_error_e* result)
+bool net_nfc_controller_check_ndef(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result)
{
if (g_interface.check_ndef != NULL)
{
}
}
-bool net_nfc_controller_read_ndef(net_nfc_target_handle_s* handle, data_s** data, net_nfc_error_e* result)
+bool net_nfc_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result)
{
if (g_interface.read_ndef != NULL)
{
}
}
-bool net_nfc_controller_write_ndef(net_nfc_target_handle_s* handle, data_s* data, net_nfc_error_e* result)
+bool net_nfc_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result)
{
if (g_interface.write_ndef != NULL)
{
}
}
-bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s* handle, net_nfc_error_e* result)
+bool net_nfc_controller_make_read_only_ndef(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
{
if (g_interface.make_read_only_ndef != NULL)
{
}
}
-bool net_nfc_controller_format_ndef(net_nfc_target_handle_s* handle, data_s* secure_key, net_nfc_error_e* result)
+bool net_nfc_controller_format_ndef(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result)
{
if (g_interface.format_ndef != NULL)
{
}
}
-bool net_nfc_controller_transceive(net_nfc_target_handle_s* handle, net_nfc_transceive_info_s* info, data_s** data, net_nfc_error_e* result)
+bool net_nfc_controller_transceive(net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result)
{
if (g_interface.transceive != NULL)
{
}
}
-bool net_nfc_controller_is_ready(net_nfc_error_e* result)
+bool net_nfc_controller_is_ready(net_nfc_error_e *result)
{
if (g_interface.is_ready != NULL)
{
}
}
-bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s * config, net_nfc_error_e* result)
+bool net_nfc_controller_llcp_config(net_nfc_llcp_config_info_s *config, net_nfc_error_e *result)
{
if (g_interface.config_llcp != NULL)
{
return false;
}
}
-bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result)
+bool net_nfc_controller_llcp_check_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
{
if (g_interface.check_llcp_status != NULL)
{
return false;
}
}
-bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s* handle, net_nfc_error_e* result)
+bool net_nfc_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
{
if (g_interface.activate_llcp != NULL)
{
return false;
}
}
-bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t* socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e* result, void * user_param)
+
+static GSList *llcp_sockets;
+
+static gint _compare_socket_info(gconstpointer a, gconstpointer b)
+{
+ int result;
+ socket_info_t *info = (socket_info_t *)a;
+
+ if (info->socket == (net_nfc_llcp_socket_t)b)
+ result = 0;
+ else
+ result = -1;
+
+ return result;
+}
+
+socket_info_t *_get_socket_info(net_nfc_llcp_socket_t socket)
+{
+ socket_info_t *result;
+ GSList *item;
+
+ item = g_slist_find_custom(llcp_sockets, GUINT_TO_POINTER(socket),
+ _compare_socket_info);
+ if (item != NULL) {
+ result = (socket_info_t *)item->data;
+ } else {
+ result = NULL;
+ }
+
+ return result;
+}
+
+socket_info_t *_add_socket_info(net_nfc_llcp_socket_t socket)
+{
+ socket_info_t *result;
+
+ _net_nfc_util_alloc_mem(result, sizeof(*result));
+ if (result != NULL) {
+ result->socket = socket;
+
+ llcp_sockets = g_slist_append(llcp_sockets, result);
+ }
+
+ return result;
+}
+
+static void _remove_socket_info(net_nfc_llcp_socket_t socket)
+{
+ GSList *item;
+
+ item = g_slist_find_custom(llcp_sockets, GUINT_TO_POINTER(socket),
+ _compare_socket_info);
+ if (item != NULL) {
+ llcp_sockets = g_slist_remove_link(llcp_sockets, item);
+ free(item->data);
+ }
+}
+
+static void _destroy_function(gpointer data)
+{
+ free(data);
+}
+
+static void _clear_socket_info()
+{
+ g_slist_free_full(llcp_sockets, _destroy_function);
+ llcp_sockets = NULL;
+}
+
+void net_nfc_controller_llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ socket_info_t *info;
+
+ info = _get_socket_info(socket);
+ if (info != NULL) {
+ if (info->err_cb != NULL) {
+ info->err_cb(socket, result, NULL, NULL, info->err_param);
+ }
+
+ _remove_socket_info(socket);
+ }
+}
+
+bool net_nfc_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
if (g_interface.create_llcp_socket != NULL)
{
- return g_interface.create_llcp_socket(socket, socketType, miu, rw, result, user_param);
+ bool ret;
+ socket_info_t *info;
+
+ info = _add_socket_info(-1);
+ if (info == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ ret = g_interface.create_llcp_socket(socket, socketType, miu, rw, result, NULL);
+ if (ret == true) {
+ info->socket = *socket;
+ info->err_cb = cb;
+ info->err_param = user_param;
+ } else {
+ _remove_socket_info(-1);
+ }
+
+ return ret;
}
else
{
return false;
}
}
-bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result)
+
+bool net_nfc_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result)
{
if (g_interface.bind_llcp_socket != NULL)
{
return false;
}
}
-bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t* service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param)
+
+void net_nfc_controller_llcp_incoming_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ socket_info_t *info = (socket_info_t *)user_param;
+
+ info = _get_socket_info(info->socket);
+ if (info != NULL) {
+ if (_add_socket_info(socket) != NULL) {
+ if (info->work_cb != NULL) {
+ info->work_cb(socket, result, NULL, NULL,
+ info->work_param);
+ }
+ } else {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ }
+ }
+}
+
+bool net_nfc_controller_llcp_listen(net_nfc_target_handle_s* handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
if (g_interface.listen_llcp_socket != NULL)
{
- return g_interface.listen_llcp_socket(handle, service_access_name, socket, result, user_param);
+ socket_info_t *info;
+
+ info = _get_socket_info(socket);
+ if (info == NULL) {
+ DEBUG_ERR_MSG("_get_socket_info failed");
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ info->work_cb = cb;
+ info->work_param = user_param;
+
+ return g_interface.listen_llcp_socket(handle, service_access_name, socket, result, info);
}
else
{
return false;
}
}
-bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e* result)
+
+bool net_nfc_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
if (g_interface.accept_llcp_socket != NULL)
{
- return g_interface.accept_llcp_socket(socket, result);
+ socket_info_t *info;
+
+ info = _get_socket_info(socket);
+ if (info == NULL) {
+ DEBUG_ERR_MSG("_get_socket_info failed");
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ info->err_cb = cb;
+ info->err_param = user_param;
+
+ return g_interface.accept_llcp_socket(socket, result, NULL);
}
else
{
}
}
-bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result)
+bool net_nfc_controller_llcp_reject(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result)
{
if (g_interface.reject_llcp != NULL)
{
- return g_interface.reject_llcp(handle, socket, result);
+ bool ret;
+
+ ret = g_interface.reject_llcp(handle, socket, result);
+ if (ret == true) {
+ _remove_socket_info(socket);
+ }
+
+ return ret;
}
else
{
}
}
-bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s * handle, net_nfc_llcp_socket_t socket, uint8_t* service_access_name, net_nfc_error_e* result, void * user_param)
+void net_nfc_controller_llcp_connected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
+
+ if (param == NULL)
+ return;
+
+ if (param->cb != NULL) {
+ param->cb(param->socket, result, NULL, NULL, param->user_param);
+ }
+
+ _net_nfc_util_free_mem(param);
+}
+
+bool net_nfc_controller_llcp_connect_by_url(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
int ret_val = 0;
if (g_interface.connect_llcp_by_url != NULL)
{
- return g_interface.connect_llcp_by_url(handle, socket, service_access_name, result, user_param);
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.connect_llcp_by_url(handle, socket, service_access_name, result, param);
}
else
{
return false;
}
}
-bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e* result, void * user_param)
+
+bool net_nfc_controller_llcp_connect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
int ret_val = 0;
if (g_interface.connect_llcp != NULL)
{
- return g_interface.connect_llcp(handle, socket, service_access_point, result, user_param);
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.connect_llcp(handle, socket, service_access_point, result, param);
}
else
{
return false;
}
}
-bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_error_e* result, void * user_param)
+
+void net_nfc_controller_llcp_disconnected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
+
+ if (param == NULL)
+ return;
+
+ if (param->cb != NULL) {
+ param->cb(param->socket, result, NULL, NULL, param->user_param);
+ }
+
+ _net_nfc_util_free_mem(param);
+}
+
+bool net_nfc_controller_llcp_disconnect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
int ret_val = 0;
ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
- DEBUG_SERVER_MSG("net_nfc_controller_llcp_disconnect pm_lock_state [%d]!!", ret_val);
+ DEBUG_SERVER_MSG("net_nfc_controller_llcp_disconnect pm_unlock_state [%d]!!", ret_val);
if (g_interface.disconnect_llcp != NULL)
{
- return g_interface.disconnect_llcp(handle, socket, result, user_param);
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.disconnect_llcp(handle, socket, result, param);
}
else
{
return false;
}
}
-bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e* result)
+
+bool net_nfc_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e *result)
{
if (g_interface.close_llcp_socket != NULL)
{
return false;
}
}
-bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param)
+
+void net_nfc_controller_llcp_received_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
+
+ if (param == NULL)
+ return;
+
+ if (param->cb != NULL) {
+ param->cb(param->socket, result, ¶m->data, data, param->user_param);
+ }
+
+ if (param->data.buffer != NULL) {
+ _net_nfc_util_free_mem(param->data.buffer);
+ }
+ _net_nfc_util_free_mem(param);
+}
+
+bool net_nfc_controller_llcp_recv(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
if (g_interface.recv_llcp != NULL)
{
- return g_interface.recv_llcp(handle, socket, data, result, user_param);
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ if (max_len > 0) {
+ _net_nfc_util_alloc_mem(param->data.buffer, max_len);
+ if (param->data.buffer == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ _net_nfc_util_free_mem(param);
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+ param->data.length = max_len;
+ }
+ param->user_param = user_param;
+
+ return g_interface.recv_llcp(handle, socket, ¶m->data, result, param);
}
else
{
return false;
}
}
-bool net_nfc_controller_llcp_send(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param)
+
+void net_nfc_controller_llcp_sent_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result, void *data, void *user_param)
+{
+ net_nfc_llcp_param_t *param = (net_nfc_llcp_param_t *)user_param;
+
+ if (param == NULL)
+ return;
+
+ if (param->cb != NULL) {
+ param->cb(param->socket, result, NULL, NULL, param->user_param);
+ }
+
+ _net_nfc_util_free_mem(param);
+}
+
+bool net_nfc_controller_llcp_send(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
if (g_interface.send_llcp != NULL)
{
- return g_interface.send_llcp(handle, socket, data, result, user_param);
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.send_llcp(handle, socket, data, result, param);
}
else
{
return false;
}
}
-bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, net_nfc_error_e* result, void * user_param)
+bool net_nfc_controller_llcp_recv_from(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint32_t max_len, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
if (g_interface.recv_from_llcp != NULL)
{
- return g_interface.recv_from_llcp(handle, socket, data, result, user_param);
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ if (max_len > 0) {
+ _net_nfc_util_alloc_mem(param->data.buffer, max_len);
+ if (param->data.buffer == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ _net_nfc_util_free_mem(param);
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+ param->data.length = max_len;
+ }
+ param->user_param = user_param;
+
+ return g_interface.recv_from_llcp(handle, socket, ¶m->data, result, param);
}
else
{
return false;
}
}
-bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, data_s* data, uint8_t service_access_point, net_nfc_error_e* result, void * user_param)
+bool net_nfc_controller_llcp_send_to(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, net_nfc_service_llcp_cb cb, void *user_param)
{
if (g_interface.send_to_llcp != NULL)
{
- return g_interface.send_to_llcp(handle, socket, data, service_access_point, result, user_param);
+ net_nfc_llcp_param_t *param = NULL;
+
+ _net_nfc_util_alloc_mem(param, sizeof(*param));
+ if (param == NULL) {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ param->socket = socket;
+ param->cb = cb;
+ param->user_param = user_param;
+
+ return g_interface.send_to_llcp(handle, socket, data, service_access_point, result, param);
}
else
{
}
}
-bool net_nfc_controller_llcp_get_remote_config(net_nfc_target_handle_s* handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e* result)
+bool net_nfc_controller_llcp_get_remote_config(net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result)
{
if (g_interface.get_remote_config != NULL)
{
return false;
}
}
-bool net_nfc_controller_llcp_get_remote_socket_info(net_nfc_target_handle_s* handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s * option, net_nfc_error_e* result)
+bool net_nfc_controller_llcp_get_remote_socket_info(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result)
{
if (g_interface.get_remote_socket_info != NULL)
{
}
-bool net_nfc_controller_sim_test(net_nfc_error_e* result)
+bool net_nfc_controller_sim_test(net_nfc_error_e *result)
{
if (g_interface.sim_test != NULL)
{
}
}
-bool net_nfc_controller_prbs_test(net_nfc_error_e* result, uint32_t tech, uint32_t rate)
+bool net_nfc_controller_prbs_test(net_nfc_error_e *result, uint32_t tech, uint32_t rate)
{
if (g_interface.prbs_test != NULL)
{
}
}
-bool net_nfc_controller_test_mode_on(net_nfc_error_e* result)
+bool net_nfc_controller_test_mode_on(net_nfc_error_e *result)
{
if (g_interface.test_mode_on != NULL)
{
}
}
-bool net_nfc_controller_test_mode_off(net_nfc_error_e* result)
+bool net_nfc_controller_test_mode_off(net_nfc_error_e *result)
{
if (g_interface.test_mode_off != NULL)
{
}
}
-bool net_nfc_controller_support_nfc(net_nfc_error_e* result)
+bool net_nfc_controller_support_nfc(net_nfc_error_e *result)
{
if (g_interface.support_nfc != NULL)
{
return false;
}
}
-
#include <pthread.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>
+#include <gio/gio.h>
#include <sys/utsname.h>
-#include "heynoti.h"
-#include "vconf.h"
-
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_service_private.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_service_vconf_private.h"
-#include "net_nfc_app_util_private.h"
-#include "net_nfc_controller_private.h"
-#include "net_nfc_util_private.h"
+#include <vconf.h>
+
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_vconf.h"
+#include "net_nfc_server_manager.h"
+#include "net_nfc_server_se.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_app_util_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_defines.h"
-#include "net_nfc_server_dispatcher_private.h"
-#include "net_nfc_server_context_private.h"
-#include "net_nfc_manager_dbus.h"
-#include "nfc-service-binding.h"
+#include "net_nfc_manager.h"
+#include "net_nfc_server.h"
-static GMainLoop *loop = NULL;
-static GObject *object = NULL;
-static DBusGConnection *connection = NULL;
-static pid_t launch_by_client = 0;
-
-static void __net_nfc_discovery_polling_cb(keynode_t *node, void *user_data);
-
-G_DEFINE_TYPE(Nfc_Service, nfc_service, G_TYPE_OBJECT)
-
-/* Just Check the assert and set the error message */
-#define __G_ASSERT(test, return_val, error, domain, error_code)\
- G_STMT_START\
- {\
- if G_LIKELY (!(test)) { \
- g_set_error (error, domain, error_code, #test); \
- return (return_val); \
- }\
- }\
- G_STMT_END
-
-GQuark nfc_service_error_quark(void)
-{
- DEBUG_MSG("nfc_service_error_quark entered");
+static gboolean use_daemon = FALSE;
- return g_quark_from_static_string("nfc_service_error");
-}
+GOptionEntry option_entries[] = {
+ { "daemon", 'd', 0, G_OPTION_ARG_NONE, &use_daemon,
+ "Use Daemon mode", NULL },
+ { NULL }
+};
-static void nfc_service_init(Nfc_Service *nfc_service)
-{
- DEBUG_MSG("nfc_service_init entered");
-}
+static GMainLoop *loop = NULL;
-static void nfc_service_class_init(Nfc_ServiceClass *nfc_service_class)
+void net_nfc_manager_quit()
{
- DEBUG_MSG("nfc_service_class_init entered");
-
- dbus_g_object_type_install_info(NFC_SERVICE_TYPE, &dbus_glib_nfc_service_object_info);
+ DEBUG_MSG("net_nfc_manager_quit kill the nfc-manager daemon!!");
+ if (loop != NULL) {
+ g_main_loop_quit(loop);
+ }
}
-gboolean nfc_service_launch(Nfc_Service *nfc_service, const pid_t pid, guint *result_val, GError **error)
+static void on_bus_acquired(GDBusConnection *connection,
+ const gchar *path,
+ gpointer user_data)
{
- DEBUG_MSG("nfc_service_launch entered");
-
- DEBUG_SERVER_MSG("nfc_service_launch NFC MANAGER PID=[%d]", getpid());
- DEBUG_SERVER_MSG("nfc_service_launch NFC MANAGER TID=[%lx]", pthread_self());
- DEBUG_SERVER_MSG("requested client pid [%d]", pid);
+ gint state;
- launch_by_client = getpid();
-
- return TRUE;
-}
+ DEBUG_MSG("bus path : %s", path);
-gboolean nfc_service_terminate(Nfc_Service *nfc_service, guint *result_val, GError **error)
-{
- int result, state;
+ net_nfc_server_gdbus_init();
- DEBUG_MSG("nfc_service_terminate entered, remain client [%d]", net_nfc_server_get_client_count());
+ net_nfc_server_controller_init();
- result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
- if (result != 0)
+ if (vconf_get_bool(VCONFKEY_NFC_STATE, &state) != 0)
{
- DEBUG_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result);
- return false;
- }
+ DEBUG_MSG("VCONFKEY_NFC_STATE is not exist");
+ net_nfc_manager_quit();
- /*TEMP CODE*/
- //if ((g_server_info.connected_client_count <=1) && (state == false))
- if (state == false)
- {
- g_main_loop_quit(loop);
-
- if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0)
- {
- DEBUG_ERR_MSG("vconf_set_bool failed");
- }
-
- DEBUG_MSG("Real nfc_service_terminate end");
- }
- else
- {
- DEBUG_MSG("Fake nfc_service_terminate end");
+ return;
}
- return TRUE;
+ net_nfc_server_vconf_init();
+
+ if (state == 1)
+ net_nfc_server_manager_set_active(TRUE);
+#ifndef ESE_ALWAYS_ON
+ else if (use_daemon == TRUE)
+ net_nfc_server_controller_deinit();
+#endif
}
-static void _net_nfc_intialize_dbus_connection()
+static void on_name_acquired(GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
{
- GError *error = NULL;
- DBusGProxy *proxy = NULL;
- guint ret = 0;
-
- g_type_init();
-
- connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (error == NULL)
- {
- object = (GObject *)g_object_new(NFC_SERVICE_TYPE, NULL);
- dbus_g_connection_register_g_object(connection, NFC_SERVICE_PATH, object);
-
- /* register service */
- proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
- if (proxy != NULL)
- {
- if (!org_freedesktop_DBus_request_name(proxy, NFC_SERVICE_NAME, 0, &ret, &error))
- {
- DEBUG_MSG("Unable to register service: %s", error->message);
- g_error_free(error);
- }
-
- g_object_unref(proxy);
- }
- else
- {
- DEBUG_MSG("dbus_g_proxy_new_for_name failed");
- }
- }
- else
- {
- DEBUG_MSG("ERROR: Can't get on system bus [%s]", error->message);
- g_error_free(error);
- }
+ DEBUG_SERVER_MSG("name : %s", name);
}
-static void _net_nfc_deintialize_dbus_connection()
+static void on_name_lost(GDBusConnection *connnection,
+ const gchar *name,
+ gpointer user_data)
{
- if (connection != NULL && object != NULL)
- {
- dbus_g_connection_unregister_g_object(connection, object);
- g_object_unref(object);
- }
+ DEBUG_SERVER_MSG("name : %s", name);
+
+ net_nfc_manager_quit();
}
-int main(int check, char* argv[])
+
+int main(int argc, char *argv[])
{
- int result = 0;
+
void *handle = NULL;
- int state = 0;
+ guint id = 0;
+ gboolean use_daemon = FALSE;
+
+ GOptionContext *option_context;
+ GError *error = NULL;
if (!g_thread_supported())
{
g_type_init();
- net_nfc_manager_init_log();
+ option_context = g_option_context_new("Nfc manager");
+ g_option_context_add_main_entries(option_context,
+ option_entries,
+ NULL);
+
+ if (g_option_context_parse(option_context,
+ &argc,
+ &argv,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not parse option: %s",
+ error->message);
+ g_error_free(error);
+
+ g_option_context_free(option_context);
+ return 0;
+ }
DEBUG_SERVER_MSG("start nfc manager");
- DEBUG_SERVER_MSG("argv0 = %s", argv[0]);
- DEBUG_SERVER_MSG("argv1 = %s", argv[1]);
+ DEBUG_SERVER_MSG("use_daemon : %d", use_daemon);
+
+ net_nfc_manager_init_log();
net_nfc_app_util_clean_storage(MESSAGE_STORAGE);
if (handle == NULL)
{
DEBUG_ERR_MSG("load plugin library is failed");
- return 0;
- }
-
- if (net_nfc_controller_support_nfc(&result) == true)
- {
- DEBUG_SERVER_MSG("NFC Support");
- if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON) != 0)
- {
- DEBUG_SERVER_MSG("VCONFKEY_NFC_FEATURE ON failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("NFC doesn't support");
- if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_OFF) != 0)
+ if (vconf_set_bool(VCONFKEY_NFC_FEATURE,
+ VCONFKEY_NFC_FEATURE_OFF) != 0)
{
- DEBUG_SERVER_MSG("VCONFKEY_NFC_FEATURE OFF failed");
+ DEBUG_ERR_MSG("VCONFKEY_NFC_FEATURE set to %d failed",
+ VCONFKEY_NFC_FEATURE_OFF);
}
- if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0)
+ if (vconf_set_bool(VCONFKEY_NFC_STATE, 0) != 0)
{
- DEBUG_SERVER_MSG("VCONFKEY_NFC_STATE failed");
+ DEBUG_ERR_MSG("VCONFKEY_NFC_STATE set to %d failed",
+ 0);
}
- net_nfc_controller_unload(handle);
- }
-
- result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
- if (result != 0)
- {
- DEBUG_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result);
-
goto EXIT;
}
- DEBUG_MSG("vconf state value [%d]", state);
-
- if (argv[1] != NULL)
- {
- if (state == FALSE && !(strncmp(argv[1], "script", 6)))
- {
- DEBUG_ERR_MSG("Init Script execute nfc manager. But State is false.");
-
- goto EXIT;
- }
- }
-
- if (net_nfc_server_ipc_initialize() != true)
+ if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON) != 0)
{
- DEBUG_ERR_MSG("nfc server ipc initialization is failed");
-
- goto EXIT;
+ DEBUG_ERR_MSG("VCONFKEY_NFC_FEATURE set to %d failed",
+ VCONFKEY_NFC_FEATURE_ON);
}
- DEBUG_SERVER_MSG("nfc server ipc init is ok");
-
- _net_nfc_intialize_dbus_connection();
+ id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+ "org.tizen.NetNfcService",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ NULL,
+ NULL);
-#if 0
- int fd = 0;
-
- fd = heynoti_init();
- DEBUG_MSG("Noti init: %d", fd);
- if (fd == -1)
- return 0;
-
- /*Power Manager send the system_wakeup noti to subscriber*/
- result = heynoti_subscribe(fd, "system_wakeup", __net_nfc_discovery_polling_cb, (void *)fd);
- DEBUG_MSG("noti add: %d", result);
-
- if (result == -1)
- return 0;
-
- result = heynoti_attach_handler(fd);
- DEBUG_MSG("attach handler : %d", result);
-
- if (result == -1)
- return 0;
-#endif
- vconf_notify_key_changed("memory/pm/state", __net_nfc_discovery_polling_cb, NULL);
-
- net_nfc_service_vconf_register_notify_listener();
-
- loop = g_main_new(TRUE);
+ loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
EXIT :
- _net_nfc_deintialize_dbus_connection();
- net_nfc_service_vconf_unregister_notify_listener();
- net_nfc_server_ipc_finalize();
- net_nfc_controller_unload(handle);
+ net_nfc_server_vconf_deinit();
+ net_nfc_server_controller_deinit();
+ net_nfc_server_gdbus_deinit();
- net_nfc_manager_fini_log();
-
- return 0;
-}
-
-static void __net_nfc_discovery_polling_cb(keynode_t *node, void *user_data)
-{
- int state;
- int pm_state = 0;
- net_nfc_error_e result;
-
- result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
- if (result != 0)
- {
- DEBUG_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result);
- }
-
- result = vconf_get_int("memory/pm/state", &pm_state);
- DEBUG_MSG("PM STATE : %d ", pm_state);
-
- DEBUG_MSG("__net_nfc_discovery_polling_cb[Enter]");
-#if 0
- if(state == TRUE)
- {
- net_nfc_request_msg_t *req_msg = NULL;
-
- _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));
-
- if (req_msg == NULL)
- {
- DEBUG_MSG("_net_nfc_util_alloc_mem[NULL]");
- return;
- }
-
- req_msg->length = sizeof(net_nfc_request_msg_t);
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP;
-
- net_nfc_dispatcher_queue_push(req_msg);
- }
- else
+ if (id)
{
- DEBUG_SERVER_MSG("Don't need to wake up. NFC is OFF!!");
+ g_bus_unown_name(id);
}
-#endif
-
- if ((pm_state == 1) || (pm_state == 3))/*Screen On*/
- {
- net_nfc_request_msg_t *req_msg = NULL;
-
- _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));
-
- if (req_msg == NULL)
- {
- DEBUG_MSG("_net_nfc_util_alloc_mem[NULL]");
- return;
- }
- req_msg->length = sizeof(net_nfc_request_msg_t);
- req_msg->user_param = pm_state;
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP;
+ net_nfc_controller_unload(handle);
- net_nfc_dispatcher_queue_push(req_msg);
- }
- else
- {
- DEBUG_MSG("Do not anything!!");
- }
+ net_nfc_manager_fini_log();
- DEBUG_MSG("__net_nfc_discovery_polling_cb[Out]");
-}
+ g_option_context_free(option_context);
+ return 0;
+}
\ No newline at end of file
#include "svi.h"
#include "wav_player.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_manager_util_private.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_manager_util_internal.h"
static void _play_sound_callback(int id, void *data)
{
}
}
}
-
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gio/gio.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server.h"
+#include "net_nfc_server_manager.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_ndef.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_transceive.h"
+#include "net_nfc_server_test.h"
+#include "net_nfc_server_handover.h"
+#include "net_nfc_server_se.h"
+#include "net_nfc_server_snep.h"
+#include "net_nfc_server_system_handler.h"
+#include "net_nfc_server_context_internal.h"
+
+static GDBusConnection *connection = NULL;
+static guint subscribe_id;
+
+pid_t net_nfc_server_gdbus_get_pid(const char *name)
+{
+ guint pid = 0;
+ GError *error = NULL;
+ GVariant *_ret;
+
+ _ret = g_dbus_connection_call_sync(connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "GetConnectionUnixProcessID",
+ g_variant_new("(s)", name),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (_ret != NULL) {
+ g_variant_get(_ret, "(u)", &pid);
+ g_variant_unref(_ret);
+ }
+
+ return pid;
+}
+
+static void _name_owner_changed(GDBusProxy *proxy,
+ const gchar *name, const gchar *old_owner,
+ const gchar *new_owner, void *user_data)
+{
+ if (name == NULL || old_owner == NULL || new_owner == NULL) {
+ DEBUG_ERR_MSG("invalid parameter");
+
+ return;
+ }
+
+ if (strlen(new_owner) == 0) {
+ if (net_nfc_server_gdbus_check_client_is_running(old_owner)) {
+ /* unregister service */
+ net_nfc_server_llcp_unregister_services(old_owner);
+
+ /* remove client context */
+ net_nfc_server_gdbus_cleanup_client_context(old_owner);
+ }
+ }
+}
+
+static void _on_name_owner_changed(GDBusConnection *connection,
+ const gchar *sender_name, const gchar *object_path,
+ const gchar *interface_name, const gchar *signal_name,
+ GVariant *parameters, gpointer user_data)
+{
+ gchar *name;
+ gchar *old_owner;
+ gchar *new_owner;
+
+ g_variant_get(parameters,
+ "(sss)",
+ &name,
+ &old_owner,
+ &new_owner);
+
+ _name_owner_changed((GDBusProxy *)connection,
+ name, old_owner, new_owner, user_data);
+}
+
+static void _subscribe_name_owner_changed_event()
+{
+ if (connection == NULL)
+ return;
+
+ /* subscribe signal */
+ subscribe_id = g_dbus_connection_signal_subscribe(connection,
+ "org.freedesktop.DBus", /* bus name */
+ "org.freedesktop.DBus", /* interface */
+ "NameOwnerChanged", /* member */
+ "/org/freedesktop/DBus", /* path */
+ NULL, /* arg0 */
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ _on_name_owner_changed,
+ NULL, NULL);
+}
+
+static void _unsubscribe_name_owner_changed_event()
+{
+ if (connection == NULL)
+ return;
+
+ /* subscribe signal */
+ if (subscribe_id > 0) {
+ g_dbus_connection_signal_unsubscribe(connection, subscribe_id);
+ }
+}
+
+void net_nfc_server_gdbus_init(void)
+{
+ GError *error = NULL;
+
+ if (connection)
+ g_object_unref(connection);
+
+ connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (connection == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get connection %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ net_nfc_server_gdbus_init_client_context();
+
+ if (net_nfc_server_manager_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init manager");
+ return;
+ }
+
+ if (net_nfc_server_tag_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init tag");
+ return;
+ }
+
+ if (net_nfc_server_ndef_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init ndef");
+ return;
+ }
+
+ if (net_nfc_server_llcp_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init llcp");
+ return;
+ }
+
+ if (net_nfc_server_p2p_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init tag");
+ return;
+ }
+
+ if (net_nfc_server_transceive_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not initialize transceive");
+ return;
+ }
+
+ if (net_nfc_server_test_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init Test");
+ return;
+ }
+
+ if (net_nfc_server_handover_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not initialize transceive");
+ return;
+ }
+
+ if (net_nfc_server_se_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init Test");
+ return;
+ }
+
+ if (net_nfc_server_snep_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init controller thread");
+ return;
+ }
+
+ if (net_nfc_server_system_handler_init(connection) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init controller thread");
+ return;
+ }
+
+ if (net_nfc_server_controller_thread_init() == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not init controller thread");
+ return;
+ }
+
+ _subscribe_name_owner_changed_event();
+}
+
+void net_nfc_server_gdbus_deinit(void)
+{
+ _unsubscribe_name_owner_changed_event();
+
+ net_nfc_server_manager_deinit();
+ net_nfc_server_tag_deinit();
+ net_nfc_server_ndef_deinit();
+ net_nfc_server_llcp_deinit();
+ net_nfc_server_transceive_deinit();
+ net_nfc_server_test_deinit();
+ net_nfc_server_handover_deinit();
+ net_nfc_server_se_deinit();
+ net_nfc_server_snep_deinit();
+ net_nfc_server_system_handler_deinit();
+
+ net_nfc_server_gdbus_deinit_client_context();
+
+ net_nfc_server_controller_thread_deinit();
+
+ if (connection)
+ {
+ g_object_unref(connection);
+ connection = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vconf.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_manager.h"
+#include "net_nfc_manager_util_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_se.h"
+
+
+typedef struct _ControllerFuncData ControllerFuncData;
+
+struct _ControllerFuncData
+{
+ net_nfc_server_controller_func func;
+ gpointer data;
+};
+
+static gpointer controller_thread_func(gpointer user_data);
+
+static void controller_async_queue_free_func(gpointer user_data);
+
+static void controller_thread_deinit_thread_func(gpointer user_data);
+
+static void controller_target_detected_cb(void *info,
+ void *user_context);
+
+static void controller_se_transaction_cb(void *info,
+ void *user_context);
+
+static void controller_llcp_event_cb(void *info,
+ void *user_context);
+
+static void controller_init_thread_func(gpointer user_data);
+
+#ifndef ESE_ALWAYS_ON
+static void controller_deinit_thread_func(gpointer user_data);
+#endif
+
+static void restart_polling_loop_thread_func(gpointer user_data);
+
+static GAsyncQueue *controller_async_queue = NULL;
+
+static GThread *controller_thread = NULL;
+
+static gboolean controller_is_running = FALSE;
+
+static guint32 server_state = NET_NFC_SERVER_IDLE;
+
+
+static gpointer controller_thread_func(gpointer user_data)
+{
+ if (controller_async_queue == NULL)
+ {
+ g_thread_exit(NULL);
+ return NULL;
+ }
+
+ controller_is_running = TRUE;
+ while(controller_is_running)
+ {
+ ControllerFuncData *func_data;
+
+ func_data = g_async_queue_pop(controller_async_queue);
+ if (func_data->func)
+ func_data->func(func_data->data);
+
+ g_free(func_data);
+ }
+
+ g_thread_exit(NULL);
+ return NULL;
+}
+
+static void controller_async_queue_free_func(gpointer user_data)
+{
+ g_free(user_data);
+}
+
+static void controller_thread_deinit_thread_func(gpointer user_data)
+{
+ controller_is_running = FALSE;
+}
+
+/* FIXME: it works as broadcast only now */
+static void controller_target_detected_cb(void *info,
+ void *user_context)
+{
+ net_nfc_request_target_detected_t *req =
+ (net_nfc_request_target_detected_t *)info;
+
+ g_assert(info != NULL);
+
+ if (req->request_type == NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP)
+ {
+ net_nfc_server_restart_polling_loop();
+ }
+ else
+ {
+ net_nfc_server_set_target_info(info);
+
+ if (req->devType != NET_NFC_UNKNOWN_TARGET) {
+ if (req->devType == NET_NFC_NFCIP1_TARGET ||
+ req->devType == NET_NFC_NFCIP1_INITIATOR) {
+ /* llcp target detected */
+ net_nfc_server_llcp_target_detected(info);
+ } else {
+ /* tag target detected */
+ net_nfc_server_tag_target_detected(info);
+ }
+ }
+
+ /* If target detected, sound should be played. */
+ net_nfc_manager_util_play_sound(NET_NFC_TASK_START);
+ }
+
+ /* FIXME : should be removed when plugins would be fixed*/
+ _net_nfc_util_free_mem(info);
+}
+
+/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */
+static void controller_se_transaction_cb(void *info,
+ void *user_context)
+{
+ net_nfc_request_se_event_t *req = (net_nfc_request_se_event_t *)info;
+
+ g_assert(info != NULL);
+
+ req->user_param = (uint32_t)user_context;
+
+ switch(req->request_type)
+ {
+ case NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED :
+ net_nfc_server_se_detected(req);
+ break;
+
+ case NET_NFC_MESSAGE_SE_START_TRANSACTION :
+ net_nfc_server_se_transaction_received(req);
+ break;
+
+ default :
+ break;
+ }
+}
+
+/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */
+static void controller_llcp_event_cb(void *info,
+ void *user_context)
+{
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_request_msg_t *req_msg;
+
+ if (info == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp_event info");
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)info;
+ req_llcp_msg->user_param = (uint32_t) user_context;
+
+ req_msg = (net_nfc_request_msg_t *)req_llcp_msg;
+
+ switch (req_msg->request_type)
+ {
+ case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED:
+ net_nfc_server_llcp_deactivated(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_LISTEN:
+ net_nfc_server_llcp_listen(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR:
+ case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR:
+ net_nfc_server_llcp_socket_error(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_SEND:
+ case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO:
+ net_nfc_server_llcp_send(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE:
+ net_nfc_server_llcp_receive(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM:
+ net_nfc_server_llcp_receive_from(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT:
+ case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP:
+ net_nfc_server_llcp_connect(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT:
+ net_nfc_server_llcp_disconnect(req_msg);
+ break;
+ case NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT: /* currently not used */
+ break;
+ default:
+ break;
+ }
+}
+
+static void controller_init_thread_func(gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_init(&result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_init",
+ result);
+
+ net_nfc_manager_quit();
+ return;
+ }
+
+ DEBUG_SERVER_MSG("%s success [%d]",
+ "net_nfc_controller_init",
+ result);
+
+ if (net_nfc_controller_register_listener(controller_target_detected_cb,
+ controller_se_transaction_cb,
+ controller_llcp_event_cb,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_contorller_register_listener",
+ result);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("%s success !!",
+ "net_nfc_contorller_register_listener");
+ }
+
+ if (net_nfc_server_llcp_set_config(NULL) == NET_NFC_OK)
+ DEBUG_SERVER_MSG("llcp is enabled !!");
+ else
+ DEBUG_ERR_MSG("net_nfc_server_llcp_set config failed");
+}
+
+#ifndef ESE_ALWAYS_ON
+static void controller_deinit_thread_func(gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ net_nfc_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG,
+ NET_NFC_ALL_DISABLE,
+ &result);
+
+ net_nfc_server_free_target_info();
+
+ if (net_nfc_controller_deinit() == false)
+ {
+ DEBUG_ERR_MSG("%s is failed %d",
+ "net_nfc_controller_deinit",
+ result);
+ return;
+ }
+
+ DEBUG_SERVER_MSG("%s success [%d]",
+ "net_nfc_controller_deinit",
+ result);
+
+ net_nfc_manager_quit();
+}
+#endif
+
+static void restart_polling_loop_thread_func(gpointer user_data)
+{
+
+ gint state = 0;
+ gint pm_state = 0;
+
+ net_nfc_error_e result;
+
+ if (vconf_get_bool(VCONFKEY_NFC_STATE, &state) != 0)
+ DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_NFC_STATE");
+ if (state == 0)
+ return;
+
+ if (vconf_get_int(VCONFKEY_PM_STATE, &pm_state) != 0)
+ DEBUG_ERR_MSG("%s does not exist", "VCONFKEY_PM_STATE");
+
+
+ DEBUG_SERVER_MSG("net_nfc_service_restart_polling, state = [%d]",
+ pm_state);
+
+
+ if (pm_state == VCONFKEY_PM_STATE_NORMAL)
+ {
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_CONFIG,
+ NET_NFC_ALL_ENABLE,
+ &result) == true)
+ {
+ DEBUG_SERVER_MSG("polling enable");
+ }
+
+ return;
+ }
+
+ if (pm_state == VCONFKEY_PM_STATE_LCDOFF)
+ {
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_CONFIG,
+ NET_NFC_ALL_DISABLE,
+ &result) == true)
+ {
+ DEBUG_SERVER_MSG("polling disabled");
+ }
+
+ return;
+ }
+}
+
+gboolean net_nfc_server_controller_thread_init(void)
+{
+ GError *error = NULL;
+
+ controller_async_queue = g_async_queue_new_full(
+ controller_async_queue_free_func);
+
+ controller_thread = g_thread_try_new("controller_thread",
+ controller_thread_func,
+ NULL,
+ &error);
+
+ if (controller_thread == NULL)
+ {
+ DEBUG_ERR_MSG("can not create controller thread: %s",
+ error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_controller_thread_deinit(void)
+{
+ if(net_nfc_server_controller_async_queue_push(
+ controller_thread_deinit_thread_func,
+ NULL)==FALSE)
+ {
+ DEBUG_ERR_MSG("Failed to push onto the queue");
+ }
+
+ g_thread_join(controller_thread);
+ controller_thread = NULL;
+
+ g_async_queue_unref(controller_async_queue);
+ controller_async_queue = NULL;
+}
+
+void net_nfc_server_controller_init(void)
+{
+ if(net_nfc_server_controller_async_queue_push(
+ controller_init_thread_func,
+ NULL)==FALSE)
+ {
+ DEBUG_ERR_MSG("Failed to push onto the queue");
+ }
+}
+
+#ifndef ESE_ALWAYS_ON
+void net_nfc_server_controller_deinit(void)
+{
+ net_nfc_server_controller_async_queue_push(
+ controller_deinit_thread_func,
+ NULL);
+}
+#endif
+
+gboolean net_nfc_server_controller_async_queue_push(
+ net_nfc_server_controller_func func,
+ gpointer user_data)
+{
+ ControllerFuncData *func_data;
+
+ if(controller_async_queue == NULL)
+ {
+ DEBUG_ERR_MSG("controller_async_queue is not initialized");
+ return FALSE;
+ }
+
+ func_data = g_new0(ControllerFuncData, 1);
+ func_data->func = func;
+ func_data->data = user_data;
+
+ g_async_queue_push(controller_async_queue, func_data);
+
+ return TRUE;
+}
+
+void net_nfc_server_restart_polling_loop(void)
+{
+ if(net_nfc_server_controller_async_queue_push(
+ restart_polling_loop_thread_func,
+ NULL) == FALSE)
+ {
+ DEBUG_ERR_MSG("Failed to push onto the queue");
+ }
+}
+
+void net_nfc_server_set_state(guint32 state)
+{
+ if (state == NET_NFC_SERVER_IDLE)
+ server_state &= NET_NFC_SERVER_IDLE;
+ else
+ server_state |= state;
+}
+
+void net_nfc_server_unset_state(guint32 state)
+{
+ server_state &= ~state;
+}
+
+guint32 net_nfc_server_get_state(void)
+{
+ return server_state;
+}
#include <glib.h>
#include "vconf.h"
+#ifdef SECURITY_SERVER
+#include "security-server.h"
+#endif
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
+#include "net_nfc_manager.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
#include "net_nfc_util_defines.h"
-#include "net_nfc_server_context_private.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server.h"
+#include "net_nfc_server_context_internal.h"
+
-static GList *g_client_contexts = NULL;
-static pthread_mutex_t g_client_context_lock = PTHREAD_MUTEX_INITIALIZER;
+static GHashTable *client_contexts;
+static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER;
-static gint _client_context_compare_by_socket(gconstpointer a, gconstpointer b)
+static void _cleanup_client_context(gpointer data)
{
- gint result = -1;
- net_nfc_client_info_t *info = (net_nfc_client_info_t *)a;
+ net_nfc_client_context_info_t *info = data;
- if (info->socket == (int)b)
- result = 0;
- else
- result = 1;
+ if (info != NULL)
+ {
+ g_free(info->id);
+ g_free(info);
+ }
+}
- return result;
+void net_nfc_server_gdbus_init_client_context()
+{
+ pthread_mutex_lock(&context_lock);
+
+ if (client_contexts == NULL)
+ client_contexts = g_hash_table_new(g_str_hash, g_str_equal);
+
+ pthread_mutex_unlock(&context_lock);
}
-static gint _client_context_compare_by_pgid(gconstpointer a, gconstpointer b)
+void net_nfc_server_gdbus_deinit_client_context()
{
- gint result = -1;
- net_nfc_client_info_t *info = (net_nfc_client_info_t *)a;
+ pthread_mutex_lock(&context_lock);
- if (info->pgid == (pid_t)b)
- result = 0;
- else
- result = 1;
+ if (client_contexts != NULL) {
+ g_hash_table_destroy(client_contexts);
+ client_contexts = NULL;
+ }
- return result;
+ pthread_mutex_unlock(&context_lock);
}
-static void _cleanup_client_context(gpointer data)
+/* TODO */
+bool net_nfc_server_gdbus_check_privilege(GDBusMethodInvocation *invocation,
+ GVariant *privilege,
+ const char *object,
+ const char *right)
{
- net_nfc_client_info_t *info = data;
+#ifdef SECURITY_SERVER
+ data_s priv = { NULL, 0 };
+ int result;
- if (info != NULL)
- {
- if (info->channel != NULL)
- {
- g_io_channel_unref(info->channel);
- }
+ if (privilege == NULL || object == NULL || right == NULL) {
+ return false;
+ }
- /* need to check . is it necessary to remove g_source_id */
- if (info->src_id > 0)
- {
- g_source_remove(info->src_id);
- }
+ net_nfc_util_gdbus_variant_to_data_s(privilege, &priv);
- if (info->socket > 0)
- {
- shutdown(info->socket, SHUT_RDWR);
- close(info->socket);
- }
+ result = security_server_check_privilege_by_cookie((char *)priv.buffer,
+ object, right);
- DEBUG_SERVER_MSG("cleanup success : client [%d]", info->socket);
+ net_nfc_util_free_data(&priv);
- _net_nfc_util_free_mem(info);
+ if (result < 0) {
+ DEBUG_ERR_MSG("permission denied : \"%s\", \"%s\"", object, right);
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Privilege",
+ "Permission denied");
+
+ return false;
}
-}
+#endif
+ const char *id = g_dbus_method_invocation_get_sender(invocation);
-void net_nfc_server_deinit_client_context()
-{
- pthread_mutex_lock(&g_client_context_lock);
+ net_nfc_server_gdbus_add_client_context(id,
+ NET_NFC_CLIENT_ACTIVE_STATE);
- g_list_free_full(g_client_contexts, _cleanup_client_context);
+ return true;
+}
- pthread_mutex_unlock(&g_client_context_lock);
+size_t net_nfc_server_gdbus_get_client_count_no_lock()
+{
+ return g_hash_table_size(client_contexts);
}
-int net_nfc_server_get_client_count()
+size_t net_nfc_server_gdbus_get_client_count()
{
- int result = 0;
+ size_t result;
- pthread_mutex_lock(&g_client_context_lock);
+ pthread_mutex_lock(&context_lock);
- result = g_list_length(g_client_contexts);
+ result = net_nfc_server_gdbus_get_client_count_no_lock();
- pthread_mutex_unlock(&g_client_context_lock);
+ pthread_mutex_unlock(&context_lock);
return result;
}
-net_nfc_client_info_t *net_nfc_server_get_client_context(int socket)
+net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context_no_lock(
+ const char *id)
{
- net_nfc_client_info_t *result = NULL;
- GList *item = NULL;
+ net_nfc_client_context_info_t *result;
- pthread_mutex_lock(&g_client_context_lock);
+ result = g_hash_table_lookup(client_contexts, id);
- item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_by_socket);
- if (item != NULL)
- {
- result = item->data;
- }
+ return result;
+}
+
+net_nfc_client_context_info_t *net_nfc_server_gdbus_get_client_context(
+ const char *id)
+{
+ net_nfc_client_context_info_t *result;
- pthread_mutex_unlock(&g_client_context_lock);
+ pthread_mutex_lock(&context_lock);
+
+ result = net_nfc_server_gdbus_get_client_context_no_lock(id);
+
+ pthread_mutex_unlock(&context_lock);
return result;
}
-void net_nfc_server_add_client_context(pid_t pid, int socket, GIOChannel *channel, uint32_t src_id, client_state_e state)
+void net_nfc_server_gdbus_add_client_context(const char *id,
+ client_state_e state)
{
- DEBUG_SERVER_MSG("add client context");
+ pthread_mutex_lock(&context_lock);
- if (net_nfc_server_get_client_context(socket) == NULL)
+ if (net_nfc_server_gdbus_get_client_context_no_lock(id) == NULL)
{
- net_nfc_client_info_t *info = NULL;
-
- pthread_mutex_lock(&g_client_context_lock);
+ net_nfc_client_context_info_t *info = NULL;
- _net_nfc_util_alloc_mem(info, sizeof(net_nfc_client_info_t));
+ info = g_new0(net_nfc_client_context_info_t, 1);
if (info != NULL)
{
+ pid_t pid;
+
+ pid = net_nfc_server_gdbus_get_pid(id);
+ DEBUG_SERVER_MSG("added client id : [%s], pid [%d]", id, pid);
+
+ info->id = g_strdup(id);
info->pid = pid;
- info->pgid = net_nfc_util_get_current_app_pgid(pid);
- info->socket = socket;
- info->channel = channel;
- info->src_id = src_id;
+ info->pgid = getpgid(pid);
info->state = state;
info->launch_popup_state = NET_NFC_LAUNCH_APP_SELECT;
+ info->launch_popup_state_no_check = NET_NFC_LAUNCH_APP_SELECT;
- g_client_contexts = g_list_append(g_client_contexts, info);
+ g_hash_table_insert(client_contexts,
+ (gpointer)info->id,
+ (gpointer)info);
+
+ DEBUG_SERVER_MSG("current client count = [%d]",
+ net_nfc_server_gdbus_get_client_count_no_lock());
}
else
{
DEBUG_ERR_MSG("alloc failed");
}
-
- pthread_mutex_unlock(&g_client_context_lock);
- }
- else
- {
- DEBUG_ERR_MSG("client exists already [%d]", socket);
}
- DEBUG_SERVER_MSG("current client count = [%d]", g_list_length(g_client_contexts));
+ pthread_mutex_unlock(&context_lock);
}
-void net_nfc_server_cleanup_client_context(int socket)
+void net_nfc_server_gdbus_cleanup_client_context(const char *id)
{
- GList *item = NULL;
-
- DEBUG_SERVER_MSG("clean up client context");
+ net_nfc_client_context_info_t *info;
- pthread_mutex_lock(&g_client_context_lock);
+ pthread_mutex_lock(&context_lock);
- item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_by_socket);
- if (item != NULL)
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL)
{
- _cleanup_client_context(item->data);
+ DEBUG_SERVER_MSG("clean up client context, [%s, %d]", info->id,
+ info->pid);
- g_client_contexts = g_list_delete_link(g_client_contexts, item);
- }
+ g_hash_table_remove(client_contexts, id);
+
+ _cleanup_client_context(info);
- pthread_mutex_unlock(&g_client_context_lock);
+ DEBUG_SERVER_MSG("current client count = [%d]",
+ net_nfc_server_gdbus_get_client_count_no_lock());
- DEBUG_SERVER_MSG("current client count = [%d]", g_list_length(g_client_contexts));
+// /* TODO : exit when no client */
+// if (net_nfc_server_gdbus_get_client_count_no_lock() == 0)
+// {
+// /* terminate service */
+// net_nfc_manager_quit();
+// }
+ }
+
+ pthread_mutex_unlock(&context_lock);
}
-void net_nfc_server_for_each_client_context(net_nfc_server_for_each_client_cb cb, void *user_param)
+void net_nfc_server_gdbus_for_each_client_context(
+ net_nfc_server_gdbus_for_each_client_cb cb,
+ void *user_param)
{
- GList *item = NULL;
+ GHashTableIter iter;
+ char *id;
+ net_nfc_client_context_info_t *info;
- pthread_mutex_lock(&g_client_context_lock);
- item = g_list_first(g_client_contexts);
- while (item != NULL)
- {
- if (cb != NULL)
- {
- cb(item->data, user_param);
- }
- item = g_list_next(item);
+ if (cb == NULL)
+ return;
+
+ pthread_mutex_lock(&context_lock);
+
+ g_hash_table_iter_init(&iter, client_contexts);
+ while (g_hash_table_iter_next(&iter, (gpointer *)&id,
+ (gpointer *)&info) == true) {
+ cb(info, user_param);
}
- pthread_mutex_unlock(&g_client_context_lock);
+
+ pthread_mutex_unlock(&context_lock);
}
-#ifndef BROADCAST_MESSAGE
-net_nfc_target_handle_s* net_nfc_server_get_current_client_target_handle(int socket_fd)
+bool net_nfc_server_gdbus_check_client_is_running(const char *id)
{
- int i = 0;
+ return (net_nfc_server_gdbus_get_client_context(id) != NULL);
+}
- pthread_mutex_lock(&g_server_socket_lock);
+client_state_e net_nfc_server_gdbus_get_client_state(const char *id)
+{
+ net_nfc_client_context_info_t *info;
+ client_state_e state = NET_NFC_CLIENT_INACTIVE_STATE;
- net_nfc_target_handle_s* handle = NULL;
+ pthread_mutex_lock(&context_lock);
- for(; i < NET_NFC_CLIENT_MAX; i++)
- {
- if(g_client_info[i].socket == socket_fd)
- {
- handle = g_client_info[i].target_handle;
- break;
- }
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ state = info->state;
}
- pthread_mutex_unlock(&g_server_socket_lock);
+ pthread_mutex_unlock(&context_lock);
+
+ return state;
+}
+
+void net_nfc_server_gdbus_set_client_state(const char *id, client_state_e state)
+{
+ net_nfc_client_context_info_t *info;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ info->state = state;
+ }
- return handle;
+ pthread_mutex_unlock(&context_lock);
}
-bool net_nfc_server_set_current_client_target_handle(int socket_fd, net_nfc_target_handle_s* handle)
+void net_nfc_server_gdbus_set_launch_state(const char *id,
+ net_nfc_launch_popup_state_e popup_state,
+ net_nfc_launch_popup_check_e check_foreground)
{
- int i = 0;
+ net_nfc_client_context_info_t *info;
- pthread_mutex_lock(&g_server_socket_lock);
+ pthread_mutex_lock(&context_lock);
- for(; i < NET_NFC_CLIENT_MAX; i++)
- {
- if(g_client_info[i].socket == socket_fd)
- {
- g_client_info[i].target_handle = handle;
- pthread_mutex_unlock(&g_server_socket_lock);
- return true;
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ if (check_foreground == CHECK_FOREGROUND) {
+ info->launch_popup_state = popup_state;
+ } else {
+ info->launch_popup_state_no_check = popup_state;
}
}
- pthread_mutex_unlock(&g_server_socket_lock);
- return false;
+ pthread_mutex_unlock(&context_lock);
}
-#endif
-bool net_nfc_server_check_client_is_running(int socket)
+net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_launch_state(
+ const char *id)
{
-#ifdef BROADCAST_MESSAGE
- return (net_nfc_server_get_client_context(socket) != NULL);
-#else
- int client_fd = *((int *)client_context);
+ net_nfc_client_context_info_t *info;
+ net_nfc_launch_popup_state_e result = NET_NFC_LAUNCH_APP_SELECT;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ if (info->launch_popup_state_no_check ==
+ NET_NFC_NO_LAUNCH_APP_SELECT) {
+ result = NET_NFC_NO_LAUNCH_APP_SELECT;
+ } else {
+ result = info->launch_popup_state;
+ }
+ }
- if(client_fd > 0)
- return true;
- else
- return false;
-#endif
+ pthread_mutex_unlock(&context_lock);
+
+ return result;
}
-client_state_e net_nfc_server_get_client_state(int socket)
+net_nfc_launch_popup_state_e net_nfc_server_gdbus_get_client_popup_state(
+ pid_t pid)
{
- GList *item = NULL;
- client_state_e state = NET_NFC_CLIENT_INACTIVE_STATE;
+ GHashTableIter iter;
+ char *id;
+ net_nfc_launch_popup_state_e state = NET_NFC_LAUNCH_APP_SELECT;
+ net_nfc_client_context_info_t *info = NULL, *temp;
- pthread_mutex_lock(&g_client_context_lock);
+ pthread_mutex_lock(&context_lock);
- item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_by_socket);
- if (item != NULL)
- {
- state = ((net_nfc_client_info_t *)item->data)->state;
+ g_hash_table_iter_init(&iter, client_contexts);
+ while (g_hash_table_iter_next(&iter, (gpointer *)&id,
+ (gpointer *)&temp) == true) {
+ if (temp->launch_popup_state_no_check ==
+ NET_NFC_NO_LAUNCH_APP_SELECT) {
+ state = NET_NFC_NO_LAUNCH_APP_SELECT;
+ break;
+ }
+
+ if (temp->pgid == pid) {
+ info = temp;
+ break;
+ }
+ }
+
+ if (info != NULL) {
+ state = info->launch_popup_state;
}
- pthread_mutex_unlock(&g_client_context_lock);
+ pthread_mutex_unlock(&context_lock);
return state;
}
-void net_nfc_server_set_client_state(int socket, client_state_e state)
+void net_nfc_server_gdbus_increase_se_count(const char *id)
{
- GList *item = NULL;
+ net_nfc_client_context_info_t *info;
- pthread_mutex_lock(&g_client_context_lock);
+ pthread_mutex_lock(&context_lock);
- item = g_list_find_custom(g_client_contexts, (gconstpointer)socket, _client_context_compare_by_socket);
- if (item != NULL)
- {
- ((net_nfc_client_info_t *)item->data)->state = state;
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ info->ref_se++;
}
- pthread_mutex_unlock(&g_client_context_lock);
+ pthread_mutex_unlock(&context_lock);
}
-void net_nfc_server_set_launch_state(int socket, net_nfc_launch_popup_state_e popup_state)
+void net_nfc_server_gdbus_decrease_se_count(const char *id)
{
- net_nfc_client_info_t *context = net_nfc_server_get_client_context(socket);
- pthread_mutex_lock(&g_client_context_lock);
- if (context != NULL)
- {
- context->launch_popup_state = popup_state;
+ net_nfc_client_context_info_t *info;
+
+ pthread_mutex_lock(&context_lock);
+
+ info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+ if (info != NULL) {
+ info->ref_se--;
}
- pthread_mutex_unlock(&g_client_context_lock);
+
+ pthread_mutex_unlock(&context_lock);
}
-net_nfc_launch_popup_state_e net_nfc_server_get_client_popup_state(pid_t pid)
+bool net_nfc_server_gdbus_is_server_busy()
{
- GList *item = NULL;
- net_nfc_launch_popup_state_e state = NET_NFC_LAUNCH_APP_SELECT;
-
- pthread_mutex_lock(&g_client_context_lock);
-
- item = g_list_find_custom(g_client_contexts, (gconstpointer)pid, _client_context_compare_by_pgid);
- if (item != NULL)
- {
- state = ((net_nfc_client_info_t *)item->data)->launch_popup_state;
+ bool result = false;
+
+ pthread_mutex_lock(&context_lock);
+
+ if (g_hash_table_size(client_contexts) > 0) {
+ GHashTableIter iter;
+ char *id;
+ net_nfc_client_context_info_t *info;
+
+ g_hash_table_iter_init(&iter, client_contexts);
+ while (g_hash_table_iter_next(&iter, (gpointer *)&id,
+ (gpointer *)&info) == true) {
+ if (info->ref_se > 0) {
+ result = true;
+ break;
+ }
+ }
}
- pthread_mutex_unlock(&g_client_context_lock);
+ pthread_mutex_unlock(&context_lock);
- return state;
+ return result;
}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <glib.h>
-
-#include "vconf.h"
-
-#include "net_nfc_server_dispatcher_private.h"
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_controller_private.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_controller_private.h"
-#include "net_nfc_service_private.h"
-#include "net_nfc_service_llcp_private.h"
-#include "net_nfc_service_llcp_handover_private.h"
-#include "net_nfc_service_tag_private.h"
-#include "net_nfc_service_se_private.h"
-#include "net_nfc_service_test_private.h"
-#include "net_nfc_manager_util_private.h"
-#include "net_nfc_server_context_private.h"
-
-static GQueue *g_dispatcher_queue;
-static pthread_cond_t g_dispatcher_queue_cond = PTHREAD_COND_INITIALIZER;
-static pthread_mutex_t g_dispatcher_queue_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_t g_dispatcher_thread;
-
-static void *_net_nfc_dispatcher_thread_func(void *data);
-static net_nfc_request_msg_t *_net_nfc_dispatcher_queue_pop();
-
-static net_nfc_request_msg_t *_net_nfc_dispatcher_queue_pop()
-{
- net_nfc_request_msg_t *msg = NULL;
- msg = g_queue_pop_head(g_dispatcher_queue);
- return msg;
-}
-
-void net_nfc_dispatcher_queue_push(net_nfc_request_msg_t *req_msg)
-{
- pthread_mutex_lock(&g_dispatcher_queue_lock);
- g_queue_push_tail(g_dispatcher_queue, req_msg);
- pthread_cond_signal(&g_dispatcher_queue_cond);
- pthread_mutex_unlock(&g_dispatcher_queue_lock);
-}
-
-void net_nfc_dispatcher_cleanup_queue(void)
-{
- net_nfc_request_msg_t *req_msg = NULL;
-
- pthread_mutex_lock(&g_dispatcher_queue_lock);
-
- DEBUG_SERVER_MSG("cleanup dispatcher Q start");
-
- while ((req_msg = _net_nfc_dispatcher_queue_pop()) != NULL)
- {
- DEBUG_ERR_MSG("abandon request : %d", req_msg->request_type);
- _net_nfc_util_free_mem(req_msg);
- }
-
- DEBUG_SERVER_MSG("cleanup dispatcher Q end");
-
- pthread_mutex_unlock(&g_dispatcher_queue_lock);
-}
-
-void net_nfc_dispatcher_put_cleaner(void)
-{
- net_nfc_request_msg_t *req_msg = NULL;
-
- _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));
- if (req_msg != NULL)
- {
- DEBUG_SERVER_MSG("put cleaner request");
-
- req_msg->length = sizeof(net_nfc_request_msg_t);
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_CLEANER;
- net_nfc_dispatcher_queue_push(req_msg);
- }
-}
-
-static void *_net_nfc_dispatcher_copy_message(void *msg)
-{
- net_nfc_request_msg_t *origin = (net_nfc_request_msg_t *)msg;
- net_nfc_request_msg_t *result = NULL;
-
- if (origin == NULL || origin->length == 0)
- {
- return result;
- }
-
- _net_nfc_util_alloc_mem(result, origin->length);
- if (result != NULL)
- {
- memcpy(result, origin, origin->length);
- }
-
- return result;
-}
-
-bool net_nfc_dispatcher_start_thread()
-{
- net_nfc_request_msg_t *req_msg = NULL;
- pthread_attr_t attr;
- int result, state;
-
- DEBUG_SERVER_MSG("init queue");
-
- g_dispatcher_queue = g_queue_new();
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
- if (result != 0)
- {
- DEBUG_SERVER_MSG("VCONFKEY_NFC_STATE is not exist: %d ", result);
- return false;
- }
-
- DEBUG_SERVER_MSG("net_nfc_dispatcher_start_thread vconf state value [%d]", state);
-
- if (state == TRUE)
- {
- _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));
- if (req_msg == NULL)
- {
- DEBUG_ERR_MSG("alloc failed");
- return false;
- }
-
- req_msg->length = sizeof(net_nfc_request_msg_t);
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_INIT;
-
- DEBUG_SERVER_MSG("put controller init request");
- net_nfc_dispatcher_queue_push(req_msg);
- }
- else
- {
- /*Don't need to initialize the stack!!*/
- }
-
- if (pthread_create(&g_dispatcher_thread, &attr, _net_nfc_dispatcher_thread_func, NULL) != 0)
- {
- net_nfc_dispatcher_cleanup_queue();
- DEBUG_ERR_MSG("pthread_create failed");
- return false;
- }
-
- usleep(0); /* switch to new thread */
- return true;
-}
-
-static void *_net_nfc_dispatcher_thread_func(void *data)
-{
- net_nfc_request_msg_t *req_msg;
-
- DEBUG_SERVER_MSG("net_nfc_controller_thread is created ");
-
- while (1)
- {
- pthread_mutex_lock(&g_dispatcher_queue_lock);
- if ((req_msg = _net_nfc_dispatcher_queue_pop()) == NULL)
- {
- pthread_cond_wait(&g_dispatcher_queue_cond, &g_dispatcher_queue_lock);
- pthread_mutex_unlock(&g_dispatcher_queue_lock);
- continue;
- }
- pthread_mutex_unlock(&g_dispatcher_queue_lock);
-
-// DEBUG_SERVER_MSG("net_nfc_controller get command = [%d]", req_msg->request_type);
-
- switch (req_msg->request_type)
- {
- case NET_NFC_MESSAGE_SERVICE_CLEANER :
- {
- net_nfc_service_se_cleanup();
- }
- break;
-
- case NET_NFC_MESSAGE_SEND_APDU_SE :
- {
- net_nfc_service_se_send_apdu(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_GET_ATR_SE :
- {
- net_nfc_service_se_get_atr(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
- {
- net_nfc_service_se_close_se(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
- {
- net_nfc_service_se_open_se(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SET_SE :
- {
- net_nfc_service_se_set_se(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_GET_SE :
- {
- net_nfc_service_se_get_se(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_P2P_SEND :
- {
- net_nfc_request_p2p_send_t *exchanger = (net_nfc_request_p2p_send_t *)req_msg;
-
- if (net_nfc_server_is_target_connected(exchanger->handle))
- {
- if (net_nfc_service_send_exchanger_msg(exchanger) != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("net_nfc_service_send_exchanger_msg is failed");
-
- /*send result to client*/
- net_nfc_response_p2p_send_t resp_msg = { 0, };
-
- resp_msg.handle = exchanger->handle;
- resp_msg.result = NET_NFC_P2P_SEND_FAIL;
- resp_msg.trans_param = (void *)exchanger->user_param;
-
- if (net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, &resp_msg, sizeof(net_nfc_response_p2p_send_t), NULL) == true)
- {
- DEBUG_SERVER_MSG("send exchange failed message to client");
- }
- }
- }
- else
- {
- net_nfc_response_p2p_send_t resp_msg = { 0, };
-
- resp_msg.handle = exchanger->handle;
- resp_msg.result = NET_NFC_TARGET_IS_MOVED_AWAY;
- resp_msg.trans_param = (void *)exchanger->user_param;
-
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, &resp_msg, sizeof(net_nfc_response_p2p_send_t), NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_TRANSCEIVE :
- {
- net_nfc_request_transceive_t *detail = (net_nfc_request_transceive_t *)req_msg;
- net_nfc_error_e result = NET_NFC_OK;
- data_s *data = NULL;
-
- if (net_nfc_server_is_target_connected(detail->handle))
- {
- net_nfc_transceive_info_s info;
-
- if (net_nfc_util_duplicate_data(&info.trans_data, &detail->info.trans_data) == true)
- {
- bool success;
-
- DEBUG_MSG("call transceive");
- if ((success = net_nfc_controller_transceive(detail->handle, &info, &data, &result)) == true)
- {
- if (data != NULL)
- DEBUG_SERVER_MSG("trasceive data recieved [%d], Success = %d", data->length, success);
- }
- else
- {
- DEBUG_SERVER_MSG("trasceive is failed = [%d]", result);
- }
- net_nfc_util_free_data(&info.trans_data);
- }
- }
- else
- {
- result = NET_NFC_TARGET_IS_MOVED_AWAY;
- }
-
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_response_transceive_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_transceive_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
- resp.result = result;
-
- if (result == NET_NFC_OK && data != NULL)
- {
- resp.data.length = data->length;
-
- DEBUG_SERVER_MSG("send response trans msg");
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t),
- data->buffer, data->length, NULL);
- }
- else
- {
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_transceive_t), NULL);
- }
- }
-
- if (data != NULL)
- {
- net_nfc_util_free_data(data);
- _net_nfc_util_free_mem(data);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_MAKE_READ_ONLY_NDEF :
- {
- net_nfc_service_tag_make_readonly(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_IS_TAG_CONNECTED :
- {
- net_nfc_service_is_tag_connected(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO :
- {
- net_nfc_service_get_current_tag_info(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE :
- {
- net_nfc_service_get_current_target_handle(req_msg);
- }
- break;
-
- case NET_NFC_GET_SERVER_STATE :
- {
- net_nfc_service_get_server_state(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_READ_NDEF :
- {
- net_nfc_service_tag_read_ndef(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_WRITE_NDEF :
- {
- net_nfc_service_tag_write_ndef(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_FORMAT_NDEF :
- {
- net_nfc_service_tag_format_ndef(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SIM_TEST :
- {
- net_nfc_service_test_sim_test(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_GET_FIRMWARE_VERSION :
- {
- net_nfc_service_test_get_firmware_version(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_PRBS_TEST :
- {
- net_nfc_service_test_prbs_test(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SET_EEDATA :
- {
- net_nfc_service_test_set_eedata(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_DEINIT :
- {
- net_nfc_service_deinit(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_INIT :
- {
- net_nfc_service_init(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED :
- {
-#ifndef BROADCAST_MESSAGE
- net_nfc_service_standalone_mode_target_detected(req_msg);
-#endif
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP :
- {
- net_nfc_service_restart_polling(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SE_START_TRANSACTION :
- {
- net_nfc_service_se_transaction_receive(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT :
- {
- net_nfc_service_llcp_process_accept(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED :
- {
- net_nfc_service_llcp_disconnect_target(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR :
- {
- net_nfc_service_llcp_process_socket_error(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR :
- {
- net_nfc_service_llcp_process_accepted_socket_error(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_SEND :
- {
- net_nfc_service_llcp_process_send_socket(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO :
- {
- net_nfc_service_llcp_process_send_to_socket(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE :
- {
- net_nfc_service_llcp_process_receive_socket(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM :
- {
- net_nfc_service_llcp_process_receive_from_socket(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT :
- {
- net_nfc_service_llcp_process_connect_socket(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP :
- {
- net_nfc_service_llcp_process_connect_sap_socket(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT :
- {
- net_nfc_service_llcp_process_disconnect_socket(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_SE :
- {
- net_nfc_service_se_set_se(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_TERMINATION :
- {
- net_nfc_service_termination(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED :
- {
- net_nfc_service_slave_mode_target_detected(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED :
- {
- net_nfc_service_se_detected(req_msg);
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_LISTEN :
- {
- net_nfc_request_listen_socket_t *detail = (net_nfc_request_listen_socket_t *)req_msg;
- net_nfc_response_llcp_socket_error_t *error = NULL;
- net_nfc_error_e result = NET_NFC_OK;
- bool success = false;
-
- _net_nfc_util_alloc_mem(error, sizeof (net_nfc_response_llcp_socket_error_t));
- if (error == NULL)
- {
- DEBUG_SERVER_MSG("ERROR: allocation is failed");
- break;
- }
-
- error->length = sizeof(net_nfc_response_llcp_socket_error_t);
- error->client_socket = detail->client_socket;
- error->handle = detail->handle;
-
- success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &result, error);
- if (success == true)
- {
- error->oal_socket = detail->oal_socket;
- success = net_nfc_controller_llcp_bind(detail->oal_socket, detail->sap, &result);
- }
- else
- {
- _net_nfc_util_free_mem(error);
- }
-
- if (success == true)
- {
- DEBUG_SERVER_MSG("OAL socket in Listen :%d", detail->oal_socket);
- success = net_nfc_controller_llcp_listen(detail->handle, detail->service_name.buffer, detail->oal_socket, &result, error);
- }
-
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_response_listen_socket_t resp = { 0 };
-
- resp.length = sizeof(net_nfc_response_listen_socket_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.oal_socket = detail->oal_socket;
- resp.client_socket = detail->client_socket;
- resp.trans_param = detail->trans_param;
-
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_listen_socket_t), NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONNECT :
- {
- net_nfc_request_connect_socket_t *detail = (net_nfc_request_connect_socket_t *)req_msg;
- net_nfc_response_connect_socket_t *resp = NULL;
- net_nfc_response_llcp_socket_error_t *error = NULL;
- bool success = false;
-
- _net_nfc_util_alloc_mem(error, sizeof (net_nfc_response_llcp_socket_error_t));
- if (error == NULL)
- {
- DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed");
- break;
- }
-
- _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_connect_socket_t));
- if (resp == NULL)
- {
- DEBUG_SERVER_MSG("ERROR: invalid detail info or allocation is failed");
- _net_nfc_util_free_mem(error);
- break;
- }
-
- error->length = sizeof(net_nfc_response_llcp_socket_error_t);
- error->client_socket = detail->client_socket;
- error->handle = detail->handle;
-
- resp->length = sizeof(net_nfc_response_connect_socket_t);
- resp->flags = detail->flags;
- resp->result = NET_NFC_IPC_FAIL;
-
- success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp->result), error);
- if (success == true)
- {
- error->oal_socket = resp->oal_socket = detail->oal_socket;
- DEBUG_SERVER_MSG("connect client socket [%d]", detail->client_socket);
- resp->client_socket = detail->client_socket;
- resp->trans_param = detail->trans_param;
-
- success = net_nfc_controller_llcp_connect_by_url(detail->handle, detail->oal_socket, detail->service_name.buffer, &(resp->result), resp);
- if (success == false)
- {
- DEBUG_ERR_MSG("connect client socket is failed");
-
- net_nfc_controller_llcp_socket_close(resp->oal_socket, &(resp->result));
-
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_socket_t), NULL);
- }
- _net_nfc_util_free_mem(resp);
- }
- }
- else
- {
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_socket_t), NULL);
- }
-
- _net_nfc_util_free_mem(error);
- _net_nfc_util_free_mem(resp);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONNECT_SAP :
- {
- net_nfc_request_connect_sap_socket_t *detail = (net_nfc_request_connect_sap_socket_t *)req_msg;
- net_nfc_response_connect_sap_socket_t *resp = NULL;
- bool success = false;
-
- _net_nfc_util_alloc_mem(resp, sizeof(net_nfc_response_connect_sap_socket_t));
- if (resp == NULL)
- {
- DEBUG_SERVER_MSG("ERROR: allocation is failed");
- break;
- }
-
- resp->length = sizeof(net_nfc_response_connect_sap_socket_t);
- resp->flags = detail->flags;
- resp->result = NET_NFC_IPC_FAIL;
-
- success = net_nfc_controller_llcp_create_socket(&(detail->oal_socket), detail->type, detail->miu, detail->rw, &(resp->result), NULL);
- if (success == true)
- {
- resp->oal_socket = detail->oal_socket;
- resp->client_socket = detail->client_socket;
- resp->trans_param = detail->trans_param;
-
- success = net_nfc_controller_llcp_connect(detail->handle, detail->oal_socket, detail->sap, &(resp->result), resp);
- }
-
- if (success == false)
- {
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_connect_sap_socket_t), NULL);
- }
- _net_nfc_util_free_mem(resp);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_SEND :
- {
- net_nfc_request_send_socket_t *detail = (net_nfc_request_send_socket_t *)req_msg;
- data_s data = { NULL, 0 };
-
- if (net_nfc_util_duplicate_data(&data, &detail->data) == true)
- {
- net_nfc_response_send_socket_t *resp = NULL;
-
- _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_send_socket_t));
- if (resp != NULL)
- {
- resp->length = sizeof(net_nfc_response_send_socket_t);
- resp->flags = detail->flags;
- resp->result = NET_NFC_IPC_FAIL;
- resp->client_socket = detail->client_socket;
- resp->trans_param = detail->trans_param;
-
- if (net_nfc_controller_llcp_send(detail->handle, detail->oal_socket, &data, &(resp->result), resp) == false)
- {
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_send_socket_t), NULL);
- }
- _net_nfc_util_free_mem(resp);
- }
- }
-
- net_nfc_util_free_data(&data);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_RECEIVE :
- {
- net_nfc_request_receive_socket_t *detail = (net_nfc_request_receive_socket_t *)req_msg;
- net_nfc_response_receive_socket_t *resp = NULL;
-
- _net_nfc_util_alloc_mem(resp, sizeof (net_nfc_response_receive_socket_t));
- if (resp == NULL)
- {
- DEBUG_SERVER_MSG("ERROR: allocation is failed");
- break;
- }
-
- resp->length = sizeof(net_nfc_response_receive_socket_t);
- resp->flags = detail->flags;
- resp->result = NET_NFC_IPC_FAIL;
- resp->client_socket = detail->client_socket;
- resp->trans_param = detail->trans_param;
- resp->data.length = detail->req_length;
- _net_nfc_util_alloc_mem(resp->data.buffer, detail->req_length);
- if (resp->data.buffer == NULL)
- {
- DEBUG_SERVER_MSG("ERROR: allocation is failed");
- _net_nfc_util_free_mem(resp);
- break;
- }
-
- if (net_nfc_controller_llcp_recv(detail->handle, detail->oal_socket, &(resp->data), &(resp->result), resp) == false)
- {
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)resp, sizeof(net_nfc_response_receive_socket_t), NULL);
- }
- _net_nfc_util_free_mem(resp->data.buffer);
- _net_nfc_util_free_mem(resp);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE :
- {
- net_nfc_request_close_socket_t *detail = (net_nfc_request_close_socket_t *)req_msg;
- net_nfc_error_e result = NET_NFC_OK;
-
- DEBUG_SERVER_MSG("socket close :: NET_NFC_MESSAGE_SERVICE_LLCP_CLOSE");
- net_nfc_controller_llcp_socket_close(detail->oal_socket, &result);
-
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_response_close_socket_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_close_socket_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.client_socket = detail->client_socket;
- resp.trans_param = detail->trans_param;
-
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_close_socket_t), NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_DISCONNECT : /* change resp to local variable. if there is some problem, check this first. */
- {
- net_nfc_request_disconnect_socket_t *detail = (net_nfc_request_disconnect_socket_t *)req_msg;
- net_nfc_request_disconnect_socket_t *context = NULL;
- net_nfc_error_e result = NET_NFC_OK;
-
- context = _net_nfc_dispatcher_copy_message(detail);
- if (context == NULL)
- {
- DEBUG_ERR_MSG("alloc failed");
- break;
- }
-
- if (net_nfc_controller_llcp_disconnect(detail->handle, detail->oal_socket, &result, &context) == false)
- {
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_response_disconnect_socket_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_disconnect_socket_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.client_socket = detail->client_socket;
- resp.trans_param = detail->trans_param;
-
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_disconnect_socket_t), NULL);
- }
-
- _net_nfc_util_free_mem(context);
- }
-
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_ACCEPTED :
- {
- net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)req_msg;
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_controller_llcp_accept(detail->incomming_socket, &result);
-
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_response_accept_socket_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_accept_socket_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
- resp.result = result;
- resp.client_socket = detail->client_socket;
-
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_accept_socket_t), NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_LLCP_CONFIG :
- {
- net_nfc_request_config_llcp_t *detail = (net_nfc_request_config_llcp_t *)req_msg;
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_controller_llcp_config(&(detail->config), &result);
-
- if (net_nfc_server_check_client_is_running(detail->client_fd))
- {
- net_nfc_response_config_llcp_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_config_llcp_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
- resp.result = result;
-
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_config_llcp_t), NULL);
- }
- }
- break;
-
- case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
- {
- net_nfc_request_connection_handover_t *detail = (net_nfc_request_connection_handover_t *)req_msg;
- net_nfc_error_e result = NET_NFC_OK;
-
- net_nfc_request_msg_t *param = NULL;
-
- if ((param = _net_nfc_dispatcher_copy_message(detail)) == NULL)
- {
- DEBUG_ERR_MSG("alloc failed");
- break;
- }
-
- if ((result = net_nfc_service_llcp_handover_send_request_msg((net_nfc_request_connection_handover_t *)param)) != NET_NFC_OK)
- {
- if (net_nfc_server_check_client_is_running(req_msg->client_fd))
- {
- net_nfc_response_connection_handover_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_connection_handover_t);
- resp.flags = detail->flags;
- resp.user_param = detail->user_param;
- resp.result = result;
- resp.event = NET_NFC_OPERATION_FAIL;
- resp.type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- net_nfc_send_response_msg(req_msg->client_fd, req_msg->request_type, (void *)&resp, sizeof(net_nfc_response_connection_handover_t), NULL);
- }
- }
-
- _net_nfc_util_free_mem(param);
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_WATCH_DOG :
- {
- net_nfc_service_watch_dog(req_msg);
- continue;
- }
- break;
-
- default :
- break;
- }
-
- /*need to free req_msg*/
- _net_nfc_util_free_mem(req_msg);
- }
-
- return (void *)NULL;
-}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_process_handover.h"
+#include "net_nfc_server_handover.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_context_internal.h"
+
+static NetNfcGDbusHandover *handover_skeleton = NULL;
+
+static void handover_request_thread_func(gpointer user_data);
+
+static gboolean handover_handle_request(NetNfcGDbusHandover *hdover,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ gint32 arg_type,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static void handover_request_thread_func(gpointer user_data)
+{
+ HandoverRequestData *handover_data;
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e error = NET_NFC_OK;
+
+ handover_data = (HandoverRequestData *)user_data;
+
+ if (handover_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot send Handover data");
+
+ return;
+ }
+
+ if (handover_data->handoverobj == NULL)
+ {
+ DEBUG_ERR_MSG("can not get Handover object");
+
+ if (handover_data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ handover_data->invocation,
+ "org.tizen.NetNfcService.Handover.DataError",
+ "Handover invocation is NULL");
+
+ g_object_unref(handover_data->invocation);
+ }
+
+ g_free(handover_data);
+
+ return;
+ }
+
+ handle = GUINT_TO_POINTER(handover_data->handle);
+
+ if ((error = net_nfc_server_handover_default_client_start(
+ handle,
+ (void *)handover_data)) != NET_NFC_OK)
+ {
+ if (handover_data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ handover_data->invocation,
+ "org.tizen.NetNfcService.Handover.SendError",
+ "handover operation unsuccessfull");
+
+ g_object_unref(handover_data->invocation);
+ }
+
+ g_object_unref(handover_data->handoverobj);
+ g_free(handover_data);
+ }
+}
+
+static gboolean handover_handle_request(NetNfcGDbusHandover *hdover,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ gint32 arg_type,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ HandoverRequestData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(HandoverRequestData,1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+
+ data->handoverobj = g_object_ref(hdover);
+ data->handle = arg_handle;
+ data->type = arg_type;
+ data->invocation = g_object_ref(invocation);
+
+ if (net_nfc_server_controller_async_queue_push(
+ handover_request_thread_func, data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Handover.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->handoverobj);
+ g_object_unref(data->invocation);
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean net_nfc_server_handover_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (handover_skeleton)
+ g_object_unref(handover_skeleton);
+
+ handover_skeleton = net_nfc_gdbus_handover_skeleton_new();
+
+ g_signal_connect(handover_skeleton,
+ "handle-request",
+ G_CALLBACK(handover_handle_request),
+ NULL);
+
+ if (g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(handover_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Handover",
+ &error) == FALSE)
+ {
+ g_error_free(error);
+ g_object_unref(handover_skeleton);
+ handover_skeleton = NULL;
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_handover_deinit(void)
+{
+ if (handover_skeleton)
+ {
+ g_object_unref(handover_skeleton);
+ handover_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "bluetooth-api.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_util_handover.h"
+#include "net_nfc_server_handover_internal.h"
+#include "net_nfc_server_llcp.h"
+
+
+typedef struct _net_nfc_handover_bt_get_context_t
+{
+ int step;
+ net_nfc_error_e result;
+ net_nfc_conn_handover_carrier_state_e cps;
+ net_nfc_server_handover_get_carrier_record_cb cb;
+ ndef_record_s *carrier;
+ uint32_t aux_data_count;
+ ndef_record_s *aux_data;
+ void *user_param;
+}
+net_nfc_handover_bt_get_context_t;
+
+typedef struct _net_nfc_handover_bt_process_context_t
+{
+ int step;
+ net_nfc_error_e result;
+ net_nfc_server_handover_process_carrier_record_cb cb;
+ ndef_record_s *carrier;
+ data_s data;
+ bluetooth_device_address_t addr;
+ void *user_param;
+}
+net_nfc_handover_bt_process_context_t;
+
+
+static int _net_nfc_handover_bt_get_carrier_record(
+ net_nfc_handover_bt_get_context_t *context);
+static int _net_nfc_handover_bt_process_carrier_record(
+ net_nfc_handover_bt_process_context_t *context);
+
+
+static net_nfc_error_e _net_nfc_handover_bt_get_oob_data(
+ net_nfc_carrier_config_s *config,
+ bt_oob_data_t *oob)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ data_s hash = { NULL, 0 };
+ data_s randomizer = { NULL, 0 };
+
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if (config == NULL || oob == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ memset(oob, 0, sizeof(bt_oob_data_t));
+
+ if ((result = net_nfc_util_get_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_C,
+ (uint16_t *)&hash.length,
+ &hash.buffer)) == NET_NFC_OK)
+ {
+ if (hash.length == 16)
+ {
+ DEBUG_MSG("hash.length == 16");
+
+ NET_NFC_REVERSE_ORDER_16_BYTES(hash.buffer);
+
+ oob->hash_len = MIN(sizeof(oob->hash), hash.length);
+ memcpy(oob->hash, hash.buffer, oob->hash_len);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("hash.length error : [%d] bytes", hash.length);
+ }
+ }
+
+ if ((result = net_nfc_util_get_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_R,
+ (uint16_t *)&randomizer.length,
+ &randomizer.buffer)) == NET_NFC_OK)
+ {
+ if (randomizer.length == 16)
+ {
+ DEBUG_MSG("randomizer.length == 16");
+
+ NET_NFC_REVERSE_ORDER_16_BYTES(randomizer.buffer);
+
+ oob->randomizer_len = MIN(sizeof(oob->randomizer), randomizer.length);
+ memcpy(oob->randomizer, randomizer.buffer, oob->randomizer_len);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("randomizer.length error :"
+ " [%d] bytes", randomizer.length);
+ }
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return result;
+}
+
+static void _net_nfc_handover_bt_get_carrier_config_cb(
+ int event,
+ bluetooth_event_param_t *param,
+ void *user_data)
+{
+ net_nfc_handover_bt_get_context_t *context =
+ (net_nfc_handover_bt_get_context_t *)user_data;
+
+ LOGD("[%s] START", __func__);
+
+ if (context == NULL)
+ {
+ DEBUG_SERVER_MSG("user_data is null");
+ LOGD("[%s] END", __func__);
+ return;
+ }
+
+ switch (event)
+ {
+ case BLUETOOTH_EVENT_ENABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
+ if (context->step == NET_NFC_LLCP_STEP_02)
+ {
+ _net_nfc_handover_bt_get_carrier_record(context);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("step is incorrect");
+ }
+ break;
+
+ case BLUETOOTH_EVENT_DISABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
+ break;
+
+ default :
+ DEBUG_SERVER_MSG("unhandled bt event [%d],"
+ "[0x%04x]", event, param->result);
+ break;
+ }
+
+ LOGD("[%s] END", __func__);
+}
+
+static net_nfc_error_e _net_nfc_handover_bt_create_config_record(
+ ndef_record_s **record)
+{
+ bluetooth_device_address_t bt_addr = { { 0, } };
+ net_nfc_carrier_config_s *config = NULL;
+ net_nfc_error_e result;
+
+ /* append config to ndef message */
+ if ((result = bluetooth_get_local_address(&bt_addr))
+ == BLUETOOTH_ERROR_NONE)
+ {
+ if ((result = net_nfc_util_create_carrier_config(
+ &config,
+ NET_NFC_CONN_HANDOVER_CARRIER_BT)) == NET_NFC_OK)
+ {
+ bt_oob_data_t oob = { { 0 }, };
+
+ NET_NFC_REVERSE_ORDER_6_BYTES(bt_addr.addr);
+
+ if ((result = net_nfc_util_add_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_ADDRESS,
+ sizeof(bt_addr.addr), bt_addr.addr)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_add_carrier"
+ "_config_property failed"
+ "[%d]", result);
+ }
+
+ /* get oob data */
+ if (bluetooth_oob_read_local_data(&oob) == BLUETOOTH_ERROR_NONE)
+ {
+ if (oob.hash_len == 16 && oob.randomizer_len == 16)
+ {
+ DEBUG_SERVER_MSG("oob.hash_len "
+ "[%d]", oob.hash_len);
+ DEBUG_SERVER_MSG("oob.randomizer_len"
+ " [%d]", oob.randomizer_len);
+
+ NET_NFC_REVERSE_ORDER_16_BYTES(oob.hash);
+
+ if ((result =
+ net_nfc_util_add_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_C,
+ oob.hash_len, oob.hash)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_add_carrier"
+ "_config_property failed"
+ " [%d]",result);
+ }
+
+ NET_NFC_REVERSE_ORDER_16_BYTES(oob.randomizer);
+
+ if ((result = net_nfc_util_add_carrier_config_property(
+ config,
+ NET_NFC_BT_ATTRIBUTE_OOB_HASH_R,
+ oob.randomizer_len,
+ oob.randomizer)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_add_carrier"
+ "_config_property failed"
+ " [%d]",result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("abnormal oob data, skip... [%d]", result);
+ }
+ }
+
+ if ((result = net_nfc_util_create_ndef_record_with_carrier_config(
+ record,
+ config)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_ndef_record"
+ "_with_carrier_config failed"
+ "[%d]",result);
+ }
+
+ net_nfc_util_free_carrier_config(config);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_carrier_config failed "
+ "[%d]", result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth_get_local_address failed"
+ " [%d]", result);
+ result = NET_NFC_OPERATION_FAIL;
+ }
+
+ return result;
+}
+
+static int _net_nfc_handover_bt_get_carrier_record(
+ net_nfc_handover_bt_get_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
+ {
+ DEBUG_ERR_MSG("context->result is error"
+ " [%d]", context->result);
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ }
+
+ switch (context->step)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_MSG("STEP [1]");
+
+ if (bluetooth_register_callback(
+ _net_nfc_handover_bt_get_carrier_config_cb,
+ context) >= BLUETOOTH_ERROR_NONE)
+ {
+ context->step = NET_NFC_LLCP_STEP_02;
+ context->result = NET_NFC_OK;
+
+ if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED)
+ {
+ bluetooth_enable_adapter();
+ }
+ else
+ {
+ DEBUG_MSG("bluetooth is enabled already");
+
+ /* do next step */
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bt_get_carrier_record,
+ (gpointer)context);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth_register_callback failed");
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OPERATION_FAIL;
+
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bt_get_carrier_record,
+ (gpointer)context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_MSG("STEP [2]");
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+
+ /* append config to ndef message */
+ if ((context->result =
+ _net_nfc_handover_bt_create_config_record(
+ &context->carrier)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_ch_create_bt_config_record failed"
+ "[%d]", context->result);
+ }
+
+ /* complete and return to upper step */
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bt_get_carrier_record,
+ (gpointer)context);
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_MSG("STEP return");
+
+ /* unregister current callback */
+ bluetooth_unregister_callback();
+
+ /* complete and return to upper step */
+ context->cb(context->result,
+ context->cps,
+ context->carrier,
+ context->aux_data_count,
+ context->aux_data,
+ context->user_param);
+ break;
+
+ default :
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+net_nfc_error_e net_nfc_server_handover_bt_get_carrier_record(
+ net_nfc_server_handover_get_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_handover_bt_get_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->cb = cb;
+ context->user_param = user_param;
+ context->step = NET_NFC_LLCP_STEP_01;
+ /* TODO : check cps of bt */
+ context->cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
+
+ g_idle_add((GSourceFunc)_net_nfc_handover_bt_get_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
+static bool _net_nfc_handover_bt_check_bond_device(
+ bluetooth_device_address_t *address)
+{
+ bool result = false;
+ int ret;
+ GPtrArray *devinfo = NULL;
+
+ LOGD("[%s] START", __func__);
+
+ /* allocate the g_pointer_array */
+ devinfo = g_ptr_array_new();
+
+ ret = bluetooth_get_bonded_device_list(&devinfo);
+ if (ret == BLUETOOTH_ERROR_NONE)
+ {
+ int i;
+ bluetooth_device_info_t *ptr;
+
+ DEBUG_SERVER_MSG("g pointer array count :"
+ " [%d]", devinfo->len);
+
+ for (i = 0; i < devinfo->len; i++)
+ {
+ ptr = g_ptr_array_index(devinfo, i);
+ if (ptr != NULL)
+ {
+ SECURE_LOGD("Name [%s]", ptr->device_name.name);
+ DEBUG_SERVER_MSG("Major Class [%d]",
+ ptr->device_class.major_class);
+ DEBUG_SERVER_MSG("Minor Class [%d]",
+ ptr->device_class.minor_class);
+ DEBUG_SERVER_MSG("Service Class [%d]",
+ ptr->device_class.service_class);
+ DEBUG_SERVER_MSG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+ ptr->device_address.addr[0],
+ ptr->device_address.addr[1],
+ ptr->device_address.addr[2],
+ ptr->device_address.addr[3],
+ ptr->device_address.addr[4],
+ ptr->device_address.addr[5]);
+
+ /* compare selector address */
+ if (memcmp(&(ptr->device_address),
+ address,
+ sizeof(ptr->device_address)) == 0)
+ {
+ DEBUG_SERVER_MSG("Found!!!");
+ result = true;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth_get_bonded_device_list failed with"
+ " [%d]", ret);
+ }
+
+ /* free g_pointer_array */
+ g_ptr_array_free(devinfo, TRUE);
+
+ LOGD("[%s] END", __func__);
+
+ return result;
+}
+
+static void _net_nfc_handover_bt_process_carrier_record_cb(
+ int event,
+ bluetooth_event_param_t *param,
+ void *user_data)
+{
+ net_nfc_handover_bt_process_context_t *context =
+ (net_nfc_handover_bt_process_context_t *)user_data;
+
+ LOGD("[%s] START", __func__);
+
+ if (context == NULL)
+ {
+ DEBUG_SERVER_MSG("user_data is null");
+ LOGD("[%s] END", __func__);
+ return;
+ }
+
+ switch (event)
+ {
+ case BLUETOOTH_EVENT_ENABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
+ if (context->step == NET_NFC_LLCP_STEP_02)
+ {
+ _net_nfc_handover_bt_process_carrier_record(context);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("step is incorrect");
+ }
+ break;
+
+ case BLUETOOTH_EVENT_DISABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
+ break;
+
+ case BLUETOOTH_EVENT_BONDING_FINISHED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_BONDING_FINISHED, result "
+ "[0x%04x]", param->result);
+ if (context->step == NET_NFC_LLCP_STEP_03)
+ {
+ if (param->result < BLUETOOTH_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("bond failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+
+ _net_nfc_handover_bt_process_carrier_record(context);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("step is incorrect");
+ }
+ break;
+
+ default :
+ DEBUG_SERVER_MSG("unhandled bt event [%d],"
+ "[0x%04x]", event, param->result);
+ break;
+ }
+
+ LOGD("[%s] END", __func__);
+}
+
+static int _net_nfc_handover_bt_process_carrier_record(
+ net_nfc_handover_bt_process_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
+ {
+ DEBUG_ERR_MSG("context->result is error"
+ " [%d]", context->result);
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ }
+
+ switch (context->step)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_MSG("STEP [1]");
+
+ if (bluetooth_register_callback(
+ _net_nfc_handover_bt_process_carrier_record_cb,
+ context) >= BLUETOOTH_ERROR_NONE)
+ {
+ /* next step */
+ context->step = NET_NFC_LLCP_STEP_02;
+
+ if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED)
+ {
+ context->result = NET_NFC_OK;
+ bluetooth_enable_adapter();
+ }
+ else
+ {
+ /* do next step */
+ DEBUG_MSG("BT is enabled already, go next step");
+ context->result = NET_NFC_OK;
+
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bt_process_carrier_record,
+ (gpointer)context);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth_register_callback failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
+ (gpointer)context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ {
+ net_nfc_carrier_config_s *config;
+ data_s temp = { NULL, 0 };
+
+ DEBUG_MSG("STEP [2]");
+
+ net_nfc_util_create_carrier_config_from_config_record(
+ &config,
+ context->carrier);
+
+ net_nfc_util_get_carrier_config_property(config,
+ NET_NFC_BT_ATTRIBUTE_ADDRESS,
+ (uint16_t *)&temp.length, &temp.buffer);
+
+ if (temp.length == 6)
+ {
+ NET_NFC_REVERSE_ORDER_6_BYTES(temp.buffer);
+
+ memcpy(context->addr.addr,
+ temp.buffer,
+ MIN(sizeof(context->addr.addr),
+ temp.length));
+
+ if (_net_nfc_handover_bt_check_bond_device
+ (&context->addr) == true)
+ {
+ DEBUG_SERVER_MSG("already paired with"
+ " [%02x:%02x:%02x:%02x:%02x:%02x]",
+ context->addr.addr[0],
+ context->addr.addr[1],
+ context->addr.addr[2],
+ context->addr.addr[3],
+ context->addr.addr[4],
+ context->addr.addr[5]);
+
+ /* return */
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OK;
+ }
+ else
+ {
+ bt_oob_data_t oob = { { 0 } , };
+
+ if (_net_nfc_handover_bt_get_oob_data(
+ config,
+ &oob) == NET_NFC_OK)
+ {
+ /* set oob data */
+ bluetooth_oob_add_remote_data(
+ &context->addr,
+ &oob);
+ }
+
+ /* pair and send reponse */
+ context->result = NET_NFC_OK;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("bluetooth address is invalid."
+ " [%d] bytes", temp.length);
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+
+ net_nfc_util_free_carrier_config(config);
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
+ (gpointer)context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ {
+ DEBUG_MSG("STEP return");
+ data_s data = { context->addr.addr,
+ sizeof(context->addr.addr) };
+
+ /* unregister bluetooth callback */
+ bluetooth_unregister_callback();
+
+ context->cb(context->result,
+ NET_NFC_CONN_HANDOVER_CARRIER_BT,
+ &data,
+ context->user_param);
+ }
+ break;
+
+ default :
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+net_nfc_error_e net_nfc_server_handover_bt_process_carrier_record(
+ ndef_record_s *record,
+ net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_handover_bt_process_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->cb = cb;
+ context->user_param = user_param;
+ context->step = NET_NFC_LLCP_STEP_01;
+ net_nfc_util_create_record(record->TNF, &record->type_s,
+ &record->id_s, &record->payload_s, &context->carrier);
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_handover_bt_process_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
+static void _net_nfc_handover_bt_post_process_cb(int event,
+ bluetooth_event_param_t *param, void *user_data)
+{
+ net_nfc_handover_bt_process_context_t *context =
+ (net_nfc_handover_bt_process_context_t *)user_data;
+
+ LOGD("[%s] START", __func__);
+
+ if (context == NULL)
+ {
+ DEBUG_SERVER_MSG("user_data is null");
+ LOGD("[%s] END", __func__);
+ return;
+ }
+
+ switch (event)
+ {
+ case BLUETOOTH_EVENT_ENABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
+ break;
+
+ case BLUETOOTH_EVENT_DISABLED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
+ break;
+
+ case BLUETOOTH_EVENT_BONDING_FINISHED :
+ DEBUG_SERVER_MSG("BLUETOOTH_EVENT_BONDING_FINISHED,"
+ " result [0x%04x]",param->result);
+
+ if (param->result < BLUETOOTH_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("bond failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ }
+ else
+ {
+ context->result = NET_NFC_OK;
+ }
+
+ context->cb(context->result,
+ NET_NFC_CONN_HANDOVER_CARRIER_BT,
+ NULL,
+ context->user_param);
+ break;
+
+ default :
+ DEBUG_SERVER_MSG("unhandled bt event"
+ " [%d], [0x%04x]", event, param->result);
+ break;
+ }
+
+ LOGD("[%s] END", __func__);
+}
+
+net_nfc_error_e net_nfc_server_handover_bt_post_process(
+ data_s *data,
+ net_nfc_server_handover_process_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_handover_bt_process_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ bluetooth_device_address_t bt_addr;
+
+ context->cb = cb;
+ context->user_param = user_param;
+
+ memcpy(&bt_addr.addr, data->buffer, sizeof(bt_addr.addr));
+
+ if (bluetooth_register_callback(
+ _net_nfc_handover_bt_post_process_cb,
+ context) >= BLUETOOTH_ERROR_NONE)
+ {
+ bluetooth_bond_device(&bt_addr);
+ }
+ else
+ {
+ _net_nfc_util_free_mem(context);
+ result = NET_NFC_OPERATION_FAIL;
+ }
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <glib-object.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <errno.h>
-
-#include "vconf.h"
-#ifdef SECURITY_SERVER
-#include "security-server.h"
-#endif
-
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_defines.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_util_ipc.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_server_dispatcher_private.h"
-#include "net_nfc_controller_private.h"
-#include "net_nfc_manager_util_private.h"
-#include "net_nfc_server_context_private.h"
-
-/////////////////////////////
-
-/* static variable */
-#ifdef SECURITY_SERVER
-static char *cookies = NULL;
-static int cookies_size = 0;
-static gid_t gid = 0;
-#endif
-
-static pthread_mutex_t g_server_socket_lock = PTHREAD_MUTEX_INITIALIZER;
-static net_nfc_server_info_t g_server_info = { 0, };
-
-/////////////////
-
-/*define static function*/
-
-static gboolean net_nfc_server_ipc_callback_func(GIOChannel* channel, GIOCondition condition, gpointer data);
-static bool net_nfc_server_read_client_request(int client_sock_fd, net_nfc_error_e* result);
-static bool net_nfc_server_process_client_connect_request();
-
-/////////////////////////
-
-bool net_nfc_server_set_server_state(uint32_t state)
-{
- pthread_mutex_lock(&g_server_socket_lock);
-
- if (state == NET_NFC_SERVER_IDLE)
- g_server_info.state &= NET_NFC_SERVER_IDLE;
- else
- g_server_info.state |= state;
-
- pthread_mutex_unlock(&g_server_socket_lock);
-
- return true;
-}
-
-bool net_nfc_server_unset_server_state(uint32_t state)
-{
- pthread_mutex_lock(&g_server_socket_lock);
-
- g_server_info.state &= ~state;
-
- pthread_mutex_unlock(&g_server_socket_lock);
-
- return true;
-}
-
-uint32_t net_nfc_server_get_server_state()
-{
- return g_server_info.state;
-}
-
-bool net_nfc_server_ipc_initialize()
-{
- int result = 0;
-
- /* initialize server context */
- g_server_info.server_src_id = 0;
- g_server_info.server_channel = (GIOChannel *)NULL;
- g_server_info.server_sock_fd = -1;
- g_server_info.state = NET_NFC_SERVER_IDLE;
- g_server_info.target_info = NULL;
- ///////////////////////////////
-
-#ifdef USE_UNIX_DOMAIN
- struct sockaddr_un saddrun_rv;
-
- g_server_info.server_sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (g_server_info.server_sock_fd == -1)
- {
- DEBUG_SERVER_MSG("get socket is failed");
- return false;
- }
-
- net_nfc_util_set_non_block_socket(g_server_info.server_sock_fd);
-
- result = remove(NET_NFC_SERVER_DOMAIN);
-
- memset(&saddrun_rv, 0, sizeof(struct sockaddr_un));
- saddrun_rv.sun_family = AF_UNIX;
- strncpy(saddrun_rv.sun_path, NET_NFC_SERVER_DOMAIN, sizeof(saddrun_rv.sun_path) - 1);
-
- if ((result = bind(g_server_info.server_sock_fd, (struct sockaddr *)&saddrun_rv, sizeof(saddrun_rv))) < 0)
- {
- DEBUG_ERR_MSG("bind is failed");
- goto ERROR;
- }
-
- if ((result = chmod(NET_NFC_SERVER_DOMAIN, 0777)) < 0)
- {
- DEBUG_ERR_MSG("can not change permission of UNIX DOMAIN file");
- goto ERROR;
- }
-
-#else
- struct sockaddr_in serv_addr;
-
- g_server_info.server_sock_fd = socket(PF_INET, SOCK_STREAM, 0);
- if (g_server_info.server_sock_fd == -1)
- {
- DEBUG_SERVER_MSG("get socket is failed");
- return false;
- }
-
- net_nfc_util_set_non_block_socket(g_server_info.server_sock_fd);
-
- memset(&serv_addr, 0x00, sizeof(struct sockaddr_in));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_port = htons(NET_NFC_SERVER_PORT);
-
- int val = 1;
-
- if (setsockopt(g_server_info.server_sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)) == 0)
- {
- DEBUG_SERVER_MSG("reuse address");
- }
-
- if (bind(g_server_info.server_sock_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
- {
- DEBUG_ERR_MSG("bind is failed");
- goto ERROR;
- }
-#endif
-
- if ((result = listen(g_server_info.server_sock_fd, NET_NFC_CLIENT_MAX)) < 0)
- {
- DEBUG_ERR_MSG("listen is failed");
- goto ERROR;
- }
-
- GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN);
-
- if ((g_server_info.server_channel = g_io_channel_unix_new(g_server_info.server_sock_fd)) != NULL)
- {
- if ((g_server_info.server_src_id = g_io_add_watch(g_server_info.server_channel, condition, net_nfc_server_ipc_callback_func, NULL)) < 1)
- {
- DEBUG_ERR_MSG(" g_io_add_watch is failed");
- goto ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG(" g_io_channel_unix_new is failed");
- goto ERROR;
- }
-
-#ifdef SECURITY_SERVER
- gid = security_server_get_gid(NET_NFC_MANAGER_OBJECT);
- if (gid == 0)
- {
- DEBUG_ERR_MSG("get gid from security server is failed. this object is not allowed by security server");
- goto ERROR;
- }
-
- if ((cookies_size = security_server_get_cookie_size()) > 0)
- {
- _net_nfc_util_alloc_mem(cookies, cookies_size);
- if (cookies == NULL)
- {
- DEBUG_ERR_MSG("alloc failed");
- goto ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG("security_server_get_cookie_size failed");
- goto ERROR;
- }
-#endif
-
- net_nfc_dispatcher_start_thread();
- DEBUG_SERVER_MSG("server ipc is initialized");
-
- if (vconf_set_bool(NET_NFC_DISABLE_LAUNCH_POPUP_KEY, TRUE) != 0)
- DEBUG_ERR_MSG("SERVER : launch state set vconf fail");
-
- return true;
-
-ERROR :
-#ifdef SECURITY_SERVER
- if (cookies == NULL)
- {
- _net_nfc_util_free_mem(cookies);
- }
-#endif
-
- if (g_server_info.server_src_id > 0)
- {
- g_source_remove(g_server_info.server_src_id);
- g_server_info.server_src_id = 0;
- }
-
- if (g_server_info.server_channel != NULL)
- {
- g_io_channel_unref(g_server_info.server_channel);
- g_server_info.server_channel = NULL;
- }
-
- if (g_server_info.server_sock_fd != -1)
- {
- shutdown(g_server_info.server_sock_fd, SHUT_RDWR);
- close(g_server_info.server_sock_fd);
- g_server_info.server_sock_fd = -1;
- }
-
- return false;
-}
-
-void net_nfc_server_ipc_finalize()
-{
- /* cleanup client */
- net_nfc_server_deinit_client_context();
-
-#ifdef SECURITY_SERVER
- if (cookies == NULL)
- {
- _net_nfc_util_free_mem(cookies);
- }
-#endif
-
- if (g_server_info.server_src_id > 0)
- {
- g_source_remove(g_server_info.server_src_id);
- g_server_info.server_src_id = 0;
- }
-
- if (g_server_info.server_channel != NULL)
- {
- g_io_channel_unref(g_server_info.server_channel);
- g_server_info.server_channel = NULL;
- }
-
- if (g_server_info.server_sock_fd != -1)
- {
- shutdown(g_server_info.server_sock_fd, SHUT_RDWR);
- close(g_server_info.server_sock_fd);
- g_server_info.server_sock_fd = -1;
- }
-}
-
-gboolean net_nfc_server_ipc_callback_func(GIOChannel *channel, GIOCondition condition, gpointer data)
-{
- gboolean result = TRUE;
- int sock_fd = g_io_channel_unix_get_fd(channel);
-
- if ((G_IO_ERR & condition) || (G_IO_HUP & condition))
- {
- DEBUG_ERR_MSG("G_IO_ERR");
- if (sock_fd > 0)
- {
- if (sock_fd == g_server_info.server_sock_fd)
- {
- DEBUG_SERVER_MSG("server socket is closed");
-
- net_nfc_dispatcher_cleanup_queue();
- net_nfc_server_ipc_finalize();
- }
- else
- {
- DEBUG_SERVER_MSG("client socket is closed, socket [%d]", sock_fd);
-
- net_nfc_server_cleanup_client_context(sock_fd);
- }
- }
-
- result = FALSE;
- }
- else if (G_IO_NVAL & condition)
- {
- DEBUG_ERR_MSG("INVALID socket");
- result = FALSE;
- }
- else if (G_IO_IN & condition)
- {
- if (sock_fd > 0)
- {
- if (sock_fd == g_server_info.server_sock_fd)
- {
- /* client connect request */
- net_nfc_server_process_client_connect_request();
- }
- else
- {
- net_nfc_error_e result = NET_NFC_OK;
-
- if (net_nfc_server_read_client_request(sock_fd, &result) == false)
- {
- switch (result)
- {
- case NET_NFC_OPERATION_FAIL :
- DEBUG_SERVER_MSG("clear context and shutdown socket");
- net_nfc_server_cleanup_client_context(sock_fd);
- result = FALSE;
- break;
-
- default :
- DEBUG_ERR_MSG("read client request is failed = [0x%x]", result);
- net_nfc_server_cleanup_client_context(sock_fd);
- result = FALSE;
- break;
- }
- }
- }
- }
- }
-
- return result;
-}
-
-bool net_nfc_server_process_client_connect_request()
-{
- socklen_t addrlen = 0;
- int client_sock_fd = 0;
- GIOChannel *client_channel = NULL;
- uint32_t client_src_id = 0;
- pid_t client_pid = -1;
-#ifdef USE_UNIX_DOMAIN
- struct ucred uc;
- socklen_t uc_len = sizeof(uc);
-#endif
- DEBUG_SERVER_MSG("client is trying to connect to server");
-
- if (net_nfc_server_get_client_count() >= NET_NFC_CLIENT_MAX)
- {
- DEBUG_SERVER_MSG("client is fully served. no more capa is remained.");
- return false;
- }
-
- if ((client_sock_fd = accept(g_server_info.server_sock_fd, NULL, &addrlen)) < 0)
- {
- DEBUG_ERR_MSG("can not accept client");
- return false;
- }
-
-#ifdef USE_UNIX_DOMAIN
- if (!getsockopt(client_sock_fd, SOL_SOCKET, SO_PEERCRED, &uc, &uc_len))
- {
- client_pid = uc.pid;
- }
-#endif
- DEBUG_SERVER_MSG("client [%d] is accepted by server, socket[%d]",
- client_pid, client_sock_fd);
-
- GIOCondition condition = (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_IN);
-
- if ((client_channel = g_io_channel_unix_new(client_sock_fd)) != NULL)
- {
- if ((client_src_id = g_io_add_watch(client_channel, condition,
- net_nfc_server_ipc_callback_func, NULL)) < 1)
- {
- DEBUG_ERR_MSG("add io callback is failed");
- goto ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG("create new g io channel is failed");
- goto ERROR;
- }
-
- DEBUG_SERVER_MSG("client socket is bond with g_io_channel");
-
- net_nfc_server_add_client_context(client_pid, client_sock_fd,
- client_channel, client_src_id, NET_NFC_CLIENT_ACTIVE_STATE);
-
- return true;
-
-ERROR :
- if (client_channel != NULL)
- {
- g_io_channel_unref(client_channel);
- client_channel = NULL;
- }
-
- if (client_sock_fd != -1)
- {
- shutdown(client_sock_fd, SHUT_RDWR);
- close(client_sock_fd);
- client_sock_fd = -1;
- }
-
- return false;
-}
-
-int __net_nfc_server_read_util(int client_sock_fd, void **detail, size_t size)
-{
- static uint8_t flushing[128];
-
- *detail = NULL;
- _net_nfc_util_alloc_mem(*detail, size);
-
- if (*detail == NULL)
- {
- size_t read_size;
- int readbyes = size;
-
- while (readbyes > 0)
- {
- read_size = readbyes > 128 ? 128 : readbyes;
- if (net_nfc_server_recv_message_from_client(client_sock_fd, flushing, read_size) < 0)
- {
- return false;
- }
- readbyes -= read_size;
- }
- return false;
- }
-
- if (net_nfc_server_recv_message_from_client(client_sock_fd, *detail, size) < 0)
- {
- _net_nfc_util_free_mem(*detail);
- return false;
- }
- return true;
-}
-
-bool net_nfc_server_read_client_request(int client_sock_fd, net_nfc_error_e *result)
-{
- int read = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
- uint8_t *buffer = NULL;
- net_nfc_request_msg_t *req_msg = NULL;
-
- if ((read = net_nfc_server_recv_message_from_client(client_sock_fd, (void *)&length, sizeof(length))) <= 0)
- {
- DEBUG_ERR_MSG("shutdown request from client");
- *result = NET_NFC_OPERATION_FAIL;
- return false;
- }
-
- if (read != sizeof(length))
- {
- DEBUG_ERR_MSG("failed to read message length [%d]", read);
- *result = NET_NFC_IPC_FAIL;
- return false;
- }
-
- if (length > NET_NFC_MAX_MESSAGE_LENGTH)
- {
- DEBUG_ERR_MSG("too long message [%d]", length);
- *result = NET_NFC_IPC_FAIL;
- return false;
- }
-
- _net_nfc_util_alloc_mem(buffer, length);
- if (buffer == NULL)
- {
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
-
- memset(buffer, 0, length);
-
- if ((read = net_nfc_server_recv_message_from_client(client_sock_fd, (void *)buffer, length)) != length)
- {
- DEBUG_ERR_MSG("failed to read message [%d]", read);
- _net_nfc_util_free_mem(buffer);
- *result = NET_NFC_IPC_FAIL;
- return false;
- }
-
-#ifdef SECURITY_SERVER
- uint32_t cookie_len = *(uint32_t *)(buffer + offset);
- offset += sizeof(cookie_len);
-
- if (cookie_len == cookies_size && (length - offset) > cookies_size)
- {
- int error = 0;
-
- /* copy cookie */
- memcpy(cookies, buffer + offset, cookies_size);
- offset += cookies_size;
-
- /* for debug */
-#if 0
- DEBUG_SERVER_MSG("recevied cookies");
- DEBUG_MSG_PRINT_BUFFER(cookies, cookie_len);
-#endif
-
- /* check cookie */
- if ((error = security_server_check_privilege(cookies, gid)) < 0)
- {
- DEBUG_ERR_MSG("failed to authentificate client [%d]", error);
- _net_nfc_util_free_mem(buffer);
- *result = NET_NFC_SECURITY_FAIL;
- return false;
- }
- }
- else
- {
- DEBUG_ERR_MSG("there is no cookie or invalid in message");
- _net_nfc_util_free_mem(buffer);
- *result = NET_NFC_SECURITY_FAIL;
- return false;
- }
-#endif
-
- if (length > offset)
- {
- _net_nfc_util_alloc_mem(req_msg, length - offset);
- if (req_msg != NULL)
- {
- memcpy(req_msg, buffer + offset, length - offset);
- }
- else
- {
- _net_nfc_util_free_mem(buffer);
- *result = NET_NFC_ALLOC_FAIL;
- return false;
- }
- }
- else
- {
- _net_nfc_util_free_mem(buffer);
- *result = NET_NFC_IPC_FAIL;
- return false;
- }
-
- _net_nfc_util_free_mem(buffer);
-
- pid_t client_pid = -1;
-
- net_nfc_client_info_t *info;
- info = net_nfc_server_get_client_context(client_sock_fd);
- if (info != NULL)
- {
- client_pid = info->pid;
- }
- DEBUG_MSG(">>>>>>>>>>>>>>> [%d] >> SERVER (msg [%d], length [%d])", client_pid, req_msg->request_type, length);
-
-#ifdef BROADCAST_MESSAGE
- /* set client socket descriptor */
- req_msg->client_fd = client_sock_fd;
-#endif
-
- /* process exceptional case of request type */
- switch (req_msg->request_type)
- {
- case NET_NFC_MESSAGE_SERVICE_CHANGE_CLIENT_STATE :
- {
- net_nfc_request_change_client_state_t *detail = (net_nfc_request_change_client_state_t *)req_msg;
-
- net_nfc_server_set_client_state(client_sock_fd, detail->client_state);
- DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished");
-
- _net_nfc_util_free_mem(req_msg);
-
- return true;
- }
- break;
-
- case NET_NFC_MESSAGE_SERVICE_SET_LAUNCH_STATE :
- {
- net_nfc_request_set_launch_state_t *detail = (net_nfc_request_set_launch_state_t *)req_msg;
-
- net_nfc_server_set_launch_state(client_sock_fd, detail->set_launch_popup);
-
- _net_nfc_util_free_mem(req_msg);
-
- return true;
- }
- break;
-
- default :
- break;
- }
-
-#ifdef BROADCAST_MESSAGE
- net_nfc_dispatcher_queue_push(req_msg);
-#else
- /* check current client context is activated. */
- if (net_nfc_server_get_client_state(client_sock_fd) == NET_NFC_CLIENT_ACTIVE_STATE)
- {
- DEBUG_SERVER_MSG("client is activated");
- net_nfc_dispatcher_queue_push(req_msg);
- DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished");
- break;
- }
- else
- {
- DEBUG_SERVER_MSG("client is deactivated");
-
- /* free req_msg */
- _net_nfc_util_free_mem(req_msg);
-
- DEBUG_SERVER_MSG("net_nfc_server_read_client_request is finished");
- return false;
- }
-#endif
-
- return true;
-}
-
-#ifdef BROADCAST_MESSAGE
-bool net_nfc_server_send_message_to_client(int socket, void *message, int length)
-{
- int len = 0;
- bool result = true;
-
- pthread_mutex_lock(&g_server_socket_lock);
- len = send(socket, (void *)message, length, MSG_NOSIGNAL);
- pthread_mutex_unlock(&g_server_socket_lock);
-
- if (len <= 0)
- {
- uint8_t buf[1024] = { 0x00, };
-
- DEBUG_ERR_MSG("send failed : socket [%d], length [%d], [%s]", socket, length, strerror_r(errno, (char *)buf, sizeof(buf)));
- if (errno == EPIPE)
- {
- abort();
- }
- result = false;
- }
-
- return result;
-}
-#else
-bool net_nfc_server_send_message_to_client(void* message, int length)
-{
- pthread_mutex_lock(&g_server_socket_lock);
- int leng = send(g_server_info.client_sock_fd, (void *)message, length, 0);
- pthread_mutex_unlock(&g_server_socket_lock);
-
- if(leng > 0)
- {
- return true;
- }
- else
- {
- DEBUG_ERR_MSG("failed to send message, socket = [%d], msg_length = [%d]", g_server_info.client_sock_fd, length);
- return false;
- }
-}
-#endif
-
-int net_nfc_server_recv_message_from_client(int client_sock_fd, void* message, int length)
-{
- int leng = recv(client_sock_fd, message, length, 0);
-
- return leng;
-}
-
-static void _net_nfc_for_each_cb(net_nfc_client_info_t *client, void *user_param)
-{
- if (user_param != NULL)
- {
- int length = *(int *)user_param;
- uint8_t *send_buffer = ((uint8_t *)user_param) + sizeof(int);
-
- if (net_nfc_server_send_message_to_client(client->socket, send_buffer, length) == true)
- {
-// DEBUG_MSG(">>>>> TO CLIENT [%d] >>>>> (msg [%d], length [%d])", client->socket, msg_type, length);
- DEBUG_MSG("<<<<<<<<<<<<<<< [%d] << SERVER (length [%d])", client->pid, length);
- }
- }
-}
-
-#ifdef BROADCAST_MESSAGE
-bool net_nfc_broadcast_response_msg(int msg_type, ...)
-{
- va_list list;
- int total_size = 0;
- int written_size = 0;
- uint8_t *send_buffer = NULL;
-
- va_start(list, msg_type);
-
- /* total length */
- total_size += sizeof(msg_type);
- total_size += net_nfc_util_get_va_list_length(list);
-
- _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size));
-
- memcpy(send_buffer + written_size, &(total_size), sizeof(total_size));
- written_size += sizeof(total_size);
-
- memcpy(send_buffer + written_size, &(msg_type), sizeof(msg_type));
- written_size += sizeof(msg_type);
-
- written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list);
-
- va_end(list);
-
- net_nfc_server_for_each_client_context(_net_nfc_for_each_cb, send_buffer);
-
- _net_nfc_util_free_mem(send_buffer);
-
- return true;
-}
-
-bool net_nfc_send_response_msg(int socket, int msg_type, ...)
-#else
-bool net_nfc_send_response_msg(int msg_type, ...)
-#endif
-{
- va_list list;
- int total_size = 0;
- int written_size = 0;
- uint8_t *send_buffer = NULL;
- net_nfc_client_info_t *info;
-
- va_start(list, msg_type);
-
- total_size += sizeof(msg_type);
- total_size += net_nfc_util_get_va_list_length(list);
-
- _net_nfc_util_alloc_mem(send_buffer, total_size + sizeof(total_size));
-
-// memcpy(send_buffer + written_size, &(total_size), sizeof(total_size));
-// written_size += sizeof(total_size);
-
- memcpy(send_buffer + written_size, &(msg_type), sizeof(msg_type));
- written_size += sizeof(msg_type);
-
-// written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size + sizeof(total_size) - written_size, list);
- written_size += net_nfc_util_fill_va_list(send_buffer + written_size, total_size - written_size, list);
-
- va_end(list);
-
- if ((info = net_nfc_server_get_client_context(socket)) != NULL)
- {
-#ifdef BROADCAST_MESSAGE
- if (net_nfc_server_send_message_to_client(socket, (void *)send_buffer, total_size) == true)
-#else
- if (net_nfc_server_send_message_to_client((void *)send_buffer, total_size) == true)
-#endif
- {
- DEBUG_MSG("<<<<<<<<<<<<<<< [%d] << SERVER (msg [%d], length [%d])", info->pid, msg_type, total_size - sizeof(total_size));
- }
- }
- else
- {
- DEBUG_ERR_MSG("Client not found : socket [%d], length [%d]", socket, total_size + sizeof(total_size));
- }
-
- _net_nfc_util_free_mem(send_buffer);
-
- return true;
-}
-
-void net_nfc_server_set_tag_info(void *info)
-{
- net_nfc_request_target_detected_t *detail = (net_nfc_request_target_detected_t *)info;
- net_nfc_current_target_info_s *target_info = NULL;
-
- pthread_mutex_lock(&g_server_socket_lock);
-
- if (g_server_info.target_info != NULL)
- _net_nfc_util_free_mem(g_server_info.target_info);
-
- _net_nfc_util_alloc_mem(target_info, sizeof(net_nfc_current_target_info_s) + detail->target_info_values.length);
- if (target_info != NULL)
- {
- target_info->handle = detail->handle;
- target_info->devType = detail->devType;
-
- if (target_info->devType != NET_NFC_NFCIP1_INITIATOR && target_info->devType != NET_NFC_NFCIP1_TARGET)
- {
- target_info->number_of_keys = detail->number_of_keys;
- target_info->target_info_values.length = detail->target_info_values.length;
- memcpy(&target_info->target_info_values, &detail->target_info_values, target_info->target_info_values.length);
- }
-
- g_server_info.target_info = target_info;
- }
-
- pthread_mutex_unlock(&g_server_socket_lock);
-}
-
-bool net_nfc_server_is_target_connected(void *handle)
-{
- bool result = false;
-
- if (g_server_info.target_info != NULL && g_server_info.target_info->handle == handle)
- result = true;
-
- return result;
-}
-
-net_nfc_current_target_info_s *net_nfc_server_get_tag_info()
-{
- return g_server_info.target_info;
-}
-
-void net_nfc_server_free_current_tag_info()
-{
- pthread_mutex_lock(&g_server_socket_lock);
-
- _net_nfc_util_free_mem(g_server_info.target_info);
-
- pthread_mutex_unlock(&g_server_socket_lock);
-}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <pmapi.h>/*for pm lock*/
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_llcp.h"
+
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_server_process_npp.h"
+#include "net_nfc_server_process_handover.h"
+#include "net_nfc_server_tag.h"
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_context_internal.h"
+
+/* default llcp configurations */
+#define NET_NFC_LLCP_MIU 128
+#define NET_NFC_LLCP_WKS 1
+#define NET_NFC_LLCP_LTO 10
+#define NET_NFC_LLCP_OPT 0
+
+static NetNfcGDbusLlcp *llcp_skeleton = NULL;
+
+static net_nfc_llcp_config_info_s llcp_config =
+{
+ NET_NFC_LLCP_MIU,
+ NET_NFC_LLCP_WKS,
+ NET_NFC_LLCP_LTO,
+ NET_NFC_LLCP_OPT,
+};
+
+typedef struct _LlcpData LlcpData;
+
+struct _LlcpData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+};
+
+typedef struct _LlcpConfigData LlcpConfigData;
+
+struct _LlcpConfigData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint16 miu;
+ guint16 wks;
+ guint8 lto;
+ guint8 option;
+};
+
+typedef struct _LlcpListenData LlcpListenData;
+
+struct _LlcpListenData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint16 miu;
+ guint8 rw;
+ guint type;
+ guint sap;
+ gchar *service_name;
+};
+
+typedef struct _LlcpConnectData LlcpConnectData;
+
+struct _LlcpConnectData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint16 miu;
+ guint8 rw;
+ guint type;
+ gchar *service_name;
+};
+
+typedef struct _LlcpConnectSapData LlcpConnectSapData;
+
+struct _LlcpConnectSapData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint16 miu;
+ guint8 rw;
+ guint type;
+ guint sap;
+};
+
+typedef struct _LlcpSendData LlcpSendData;
+
+struct _LlcpSendData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+
+ data_s *data;
+};
+
+typedef struct _LlcpSendToData LlcpSendToData;
+
+struct _LlcpSendToData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint8 sap;
+
+ data_s *data;
+};
+
+typedef struct _LlcpReceiveData LlcpReceiveData;
+
+struct _LlcpReceiveData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+ guint32 req_length;
+};
+
+typedef struct _LlcpCloseData LlcpCloseData;
+
+struct _LlcpCloseData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+};
+
+typedef struct _LlcpDisconnectData LlcpDisconnectData;
+
+struct _LlcpDisconnectData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint32 handle;
+ guint32 client_socket;
+ guint32 oal_socket;
+};
+
+/* server_side */
+typedef struct _ServerLlcpData ServerLlcpData;
+
+struct _ServerLlcpData
+{
+ NetNfcGDbusLlcp *llcp;
+ net_nfc_request_msg_t *req_msg;
+};
+
+typedef struct _LlcpSimpleData LlcpSimpleData;
+
+struct _LlcpSimpleData
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_llcp_socket_t socket;
+ guint32 miu;
+ net_nfc_server_llcp_callback callback;
+ net_nfc_server_llcp_callback error_callback;
+ gpointer user_data;
+};
+
+
+static void llcp_add_async_queue(net_nfc_request_msg_t *req_msg,
+ net_nfc_server_controller_func func);
+
+static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_listen_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_connect_by_url_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_connect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_send_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_receive_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_receive_from_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_disconnect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+/* client method */
+static void llcp_handle_config_thread_func(gpointer user_data);
+
+static void llcp_handle_listen_thread_func(gpointer user_data);
+
+static void llcp_handle_connect_thread_func(gpointer user_data);
+
+static void llcp_handle_connect_sap_thread_func(gpointer user_data);
+
+static void llcp_handle_send_thread_func(gpointer user_data);
+
+static void llcp_handle_send_to_thread_func(gpointer user_data);
+
+static void llcp_handle_receive_thread_func(gpointer user_data);
+
+static void llcp_handle_receive_from_thread_func(gpointer user_data);
+
+static void llcp_handle_close_thread_func(gpointer user_data);
+
+static void llcp_handle_disconnect_thread_func(gpointer user_data);
+
+/* methods */
+static gboolean llcp_handle_config(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ GVariant *arg_config,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ guint8 arg_sap,
+ const gchar *arg_service_name,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ const gchar *arg_service_name,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ guint8 arg_sap,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint8 arg_sap,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint32 arg_req_length,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint32 arg_req_length,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+/* server side */
+static void llcp_deactivated_thread_func(gpointer user_data);
+
+static void llcp_listen_thread_func(gpointer user_data);
+
+static void llcp_socket_error_thread_func(gpointer user_data);
+
+static void llcp_send_thread_func(gpointer user_data);
+
+static void llcp_receive_thread_func(gpointer user_data);
+
+static void llcp_receive_from_thread_func(gpointer user_data);
+
+static void llcp_connect_thread_func(gpointer user_data);
+
+static void llcp_disconnect_thread_func(gpointer user_data);
+
+/* simple */
+static void llcp_simple_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_listen_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_connect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_server_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_send_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void llcp_simple_receive_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+
+static void llcp_add_async_queue(net_nfc_request_msg_t *req_msg,
+ net_nfc_server_controller_func func)
+{
+ ServerLlcpData *data = NULL;
+
+ if (llcp_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("%s is not initialized",
+ "net_nfc_server_llcp");
+ return;
+ }
+
+ if (req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("req msg is null");
+ }
+
+ data = g_new0(ServerLlcpData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ return;
+ }
+ data->llcp = g_object_ref(llcp_skeleton);
+ data->req_msg = req_msg;
+
+ if (net_nfc_server_controller_async_queue_push(func, data) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not push to controller thread");
+
+ if (data)
+ {
+ g_object_unref(data->llcp);
+ g_free(data->req_msg);
+ g_free(data);
+ }
+ }
+}
+
+static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ llcp_data->invocation,
+ "org.tizen.NetNfcService.SocketError",
+ "socket error");
+
+ g_object_unref(llcp_data->invocation);
+ }
+
+ if (llcp_data->llcp)
+ g_object_unref(llcp_data->llcp);
+
+ g_free(llcp_data);
+}
+
+static void llcp_listen_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpListenData *llcp_data;
+
+ llcp_data = (LlcpListenData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_listen(llcp_data->llcp,
+ llcp_data->invocation,
+ llcp_data->client_socket,
+ socket);
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data->service_name);
+ g_free(llcp_data);
+}
+
+static void llcp_connect_by_url_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpConnectData *llcp_data;
+
+ llcp_data = (LlcpConnectData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_connect(llcp_data->llcp,
+ llcp_data->invocation,
+ llcp_data->client_socket,
+ socket);
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data->service_name);
+ g_free(llcp_data);
+}
+
+static void llcp_connect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpConnectSapData *llcp_data;
+
+ llcp_data = (LlcpConnectSapData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_connect_sap(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ llcp_data->client_socket,
+ socket);
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+static void llcp_send_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_send(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ socket);
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+static void llcp_receive_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+ if (llcp_data->invocation)
+ {
+ GVariant *variant;
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ net_nfc_gdbus_llcp_complete_receive(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ variant);
+
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+static void llcp_receive_from_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ GVariant *variant;
+
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ net_nfc_gdbus_llcp_complete_receive_from(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ (guint8) (int)extra,
+ variant);
+
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+
+static void llcp_disconnect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpData *llcp_data;
+
+ llcp_data = (LlcpData *)user_param;
+
+ if (llcp_data == NULL)
+ return;
+
+ if (llcp_data->llcp)
+ {
+
+ if (llcp_data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_disconnect(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ socket);
+
+ g_object_unref(llcp_data->invocation);
+ }
+
+ g_object_unref(llcp_data->llcp);
+ }
+
+ g_free(llcp_data);
+}
+
+
+static void llcp_handle_config_thread_func(gpointer user_data)
+{
+ LlcpConfigData *data;
+
+ net_nfc_llcp_config_info_s config;
+
+ data = (LlcpConfigData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpConfigData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConfigError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+ g_free(data);
+
+ return;
+ }
+
+ config.miu = data->miu;
+ config.wks = data->wks;
+ config.lto = data->lto;
+ config.option = data->option;
+
+ if (net_nfc_server_llcp_set_config(&config) != NET_NFC_OK)
+ {
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConfigError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+ return;
+ }
+
+ if (data->invocation)
+ {
+ net_nfc_gdbus_llcp_complete_config(data->llcp,
+ data->invocation);
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+}
+
+static void llcp_handle_listen_thread_func(gpointer user_data)
+{
+ LlcpListenData *data;
+ LlcpData *error_data;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpListenData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpListenData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ListenError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data->service_name);
+ g_free(data);
+
+ return;
+ }
+
+ error_data = g_new0(LlcpData, 1);
+ if(error_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ error_data->llcp = g_object_ref(data->llcp);
+ error_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ data->type,
+ data->miu,
+ data->rw,
+ &result,
+ llcp_socket_error_cb,
+ error_data) == false)
+ {
+ DEBUG_ERR_MSG("%s fiailed [%d]",
+ "net_nfc_controller_llcp_create_socket" ,result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ListenError",
+ "can not create socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ return;
+ }
+
+ if (net_nfc_controller_llcp_bind(socket,
+ data->sap,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s fiailed [%d]",
+ "net_nfc_controller_llcp_create_socket" ,result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ListenError",
+ "can not bind socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("OAL socket in Listen : %d\n", socket);
+
+ if (net_nfc_controller_llcp_listen(GUINT_TO_POINTER(data->handle),
+ (uint8_t *)data->service_name,
+ socket,
+ &result,
+ llcp_listen_cb,
+ data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_listen",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ListenError",
+ "can not listen socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+ }
+}
+
+static void llcp_handle_connect_thread_func(gpointer user_data)
+{
+ LlcpConnectData *data;
+ LlcpData *error_data;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpConnectData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpListenData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data->service_name);
+ g_free(data);
+
+ return;
+ }
+
+ error_data = g_new0(LlcpData, 1);
+ if(error_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ error_data->llcp = g_object_ref(data->llcp);
+ error_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ data->type,
+ data->miu,
+ data->rw,
+ &result,
+ llcp_socket_error_cb,
+ error_data) == false)
+ {
+ DEBUG_ERR_MSG("%s fiailed [%d]",
+ "net_nfc_controller_llcp_create_socket" ,result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectError",
+ "can not create socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("OAL socket in Listen :%d", socket);
+
+ if (net_nfc_controller_llcp_connect_by_url(
+ GUINT_TO_POINTER(data->handle),
+ socket,
+ (uint8_t *)data->service_name,
+ &result,
+ llcp_connect_by_url_cb,
+ data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_connect_by_url",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectError",
+ "can not listen socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ g_free(error_data);
+
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+ }
+}
+
+static void llcp_handle_connect_sap_thread_func(gpointer user_data)
+{
+ LlcpConnectSapData *data;
+ LlcpData *error_data;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpConnectSapData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpConnectSapData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectSapError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ error_data = g_new0(LlcpData, 1);
+ if(error_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ error_data->llcp = g_object_ref(data->llcp);
+ error_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ data->type,
+ data->miu,
+ data->rw,
+ &result,
+ llcp_socket_error_cb,
+ error_data) == false)
+ {
+ DEBUG_ERR_MSG("%s fiailed [%d]",
+ "net_nfc_controller_llcp_create_socket" ,result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectSapError",
+ "can not create socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data);
+
+ g_free(error_data);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("OAL socket in Listen :%d", socket);
+
+ if (net_nfc_controller_llcp_connect(GUINT_TO_POINTER(data->handle),
+ socket,
+ data->sap,
+ &result,
+ llcp_connect_cb,
+ data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_connect",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ConnectSapError",
+ "can not connect socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data);
+
+ g_free(error_data);
+
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ }
+}
+
+static void llcp_handle_send_thread_func(gpointer user_data)
+{
+ LlcpSendData *data;
+ LlcpData *llcp_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpSendData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpSendData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SendError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_send(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ data->data,
+ &result,
+ llcp_send_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_send",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SendError",
+ "can not send socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+static void llcp_handle_send_to_thread_func(gpointer user_data)
+{
+ LlcpSendToData *data;
+ LlcpData *llcp_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpSendToData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpSendToData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SendToError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_send_to(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ data->data,
+ data->sap,
+ &result,
+ llcp_send_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_send_to",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SendToError",
+ "can not send socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ if (data->data)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+static void llcp_handle_receive_thread_func(gpointer user_data)
+{
+ LlcpReceiveData *data;
+ LlcpData *llcp_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpReceiveData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpReceiveData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ReceiveError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_recv(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ data->req_length,
+ &result,
+ llcp_receive_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_receive",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ReceiveError",
+ "can not receive");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+static void llcp_handle_receive_from_thread_func(gpointer user_data)
+{
+ LlcpReceiveData *data;
+ LlcpData *llcp_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpReceiveData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpReceiveData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ReceiveFromError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(data->invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_recv_from(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ data->req_length,
+ &result,
+ llcp_receive_from_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_receive",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.ReceiveFromError",
+ "can not receive");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+static void llcp_handle_close_thread_func(gpointer user_data)
+{
+ LlcpCloseData *data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpCloseData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpCloseData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.CloseError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ net_nfc_controller_llcp_socket_close(data->oal_socket,
+ &result);
+
+ net_nfc_gdbus_llcp_complete_close(data->llcp,
+ data->invocation,
+ data->client_socket);
+}
+
+static void llcp_handle_disconnect_thread_func(gpointer user_data)
+{
+ LlcpDisconnectData *data;
+ LlcpData *llcp_data;
+ int ret_val = 0;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ data = (LlcpDisconnectData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get LlcpDisconnectData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.DisconnectError",
+ "can not get llcp");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+
+ return;
+ }
+
+ if(GUINT_TO_POINTER(data->handle) == 0)
+ {
+ net_nfc_server_free_target_info();
+ ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
+ DEBUG_SERVER_MSG("net_nfc_controller_disconnect pm_unlock_state"
+ "[%d]!!", ret_val);
+ }
+
+ llcp_data = g_new0(LlcpData, 1);
+ if(llcp_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ return;
+ }
+ llcp_data->llcp = g_object_ref(data->llcp);
+ llcp_data->invocation = g_object_ref(data->invocation);
+
+ if (net_nfc_controller_llcp_disconnect(GUINT_TO_POINTER(data->handle),
+ data->oal_socket,
+ &result,
+ llcp_disconnect_cb,
+ llcp_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, [%d]",
+ "net_nfc_controller_llcp_receive",
+ result);
+
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.DisconnectError",
+ "can not disconnect socket");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ g_free(llcp_data);
+
+ return;
+ }
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ g_free(llcp_data);
+}
+
+
+static gboolean llcp_handle_config(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ GVariant *arg_config,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpConfigData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpConfigData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+
+ g_variant_get(arg_config,
+ "(qqyy)",
+ &data->miu,
+ &data->wks,
+ &data->lto,
+ &data->option);
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_config_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ guint8 arg_sap,
+ const gchar *arg_service_name,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpListenData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpListenData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->miu = arg_miu;
+ data->rw = arg_rw;
+ data->type = arg_type;
+ data->sap = arg_sap;
+ data->service_name = g_strdup(arg_service_name);
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_listen_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ const gchar *arg_service_name,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpConnectData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpConnectData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->miu = arg_miu;
+ data->rw = arg_rw;
+ data->type = arg_type;
+ data->service_name = g_strdup(arg_service_name);
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_connect_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data->service_name);
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ guint8 arg_sap,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpConnectSapData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpConnectSapData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->miu = arg_miu;
+ data->rw = arg_rw;
+ data->type = arg_type;
+ data->sap = arg_sap;
+
+ if(net_nfc_server_controller_async_queue_push(
+ llcp_handle_connect_sap_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpSendData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpSendData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+
+ data->data = net_nfc_util_gdbus_variant_to_data(arg_data);
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_send_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ if (data->data != NULL)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint8 arg_sap,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpSendToData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpSendToData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->sap = arg_sap;
+
+ data->data = net_nfc_util_gdbus_variant_to_data(arg_data);
+
+ if(net_nfc_server_controller_async_queue_push(
+ llcp_handle_send_to_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ if (data->data != NULL)
+ {
+ g_free(data->data->buffer);
+ g_free(data->data);
+ }
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint32 arg_req_length,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpReceiveData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpReceiveData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->req_length = arg_req_length;
+
+ if(net_nfc_server_controller_async_queue_push(
+ llcp_handle_receive_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ guint32 arg_req_length,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpReceiveData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpReceiveData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+ data->req_length = arg_req_length;
+
+ if(net_nfc_server_controller_async_queue_push(
+ llcp_handle_receive_from_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpCloseData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpCloseData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_close_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ guint32 arg_oal_socket,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ LlcpDisconnectData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ data = g_new0(LlcpDisconnectData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+ data->oal_socket = arg_oal_socket;
+
+ if (net_nfc_server_controller_async_queue_push(
+ llcp_handle_disconnect_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+static void llcp_deactivated_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_target_handle_s *handle;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+
+ handle = (net_nfc_target_handle_s *)req_llcp_msg->user_param;
+ if (handle == NULL)
+ {
+ DEBUG_SERVER_MSG(
+ "the target ID = [0x%p] was not connected before."
+ "current device may be a TARGET", handle);
+ }
+ else
+ {
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (net_nfc_controller_disconnect(handle, &result) == false)
+ {
+ if (result != NET_NFC_NOT_CONNECTED)
+ {
+ net_nfc_controller_exception_handler();
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("target was not connected.");
+ }
+ }
+
+ net_nfc_server_set_state(NET_NFC_SERVER_IDLE);
+ }
+
+ /* send p2p detatch */
+ net_nfc_server_p2p_detached();
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_listen_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ socket_info_t *info = NULL;
+ net_nfc_request_listen_socket_t *listen_socket;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ listen_socket = (net_nfc_request_listen_socket_t *)data->req_msg;
+
+ info = (socket_info_t *)listen_socket->user_param;
+ info = _get_socket_info(info->socket);
+
+ if (info != NULL)
+ {
+ if (_add_socket_info(listen_socket->client_socket) != NULL)
+ {
+ if (info->work_cb != NULL)
+ {
+ info->work_cb(listen_socket->client_socket,
+ listen_socket->result, NULL, NULL,info->work_param);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ }
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_socket_error_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(req_llcp_msg->llcp_socket,
+ req_llcp_msg->result,
+ NULL,
+ NULL,
+ param->user_param);
+ }
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_send_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_llcp_msg->result,
+ NULL,
+ NULL,
+ param->user_param);
+ }
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_receive_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_receive_socket_t *req_receive_socket;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_receive_socket = (net_nfc_request_receive_socket_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_receive_socket->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_receive_socket->result,
+ ¶m->data,
+ NULL,
+ param->user_param);
+ }
+
+ if (param->data.buffer)
+ g_free(param->data.buffer);
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_receive_from_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_receive_from_socket_t *req_receive_from_socket;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_receive_from_socket = (net_nfc_request_receive_from_socket_t *)
+ data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_receive_from_socket->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_receive_from_socket->result,
+ ¶m->data,
+ (void *)(int)req_receive_from_socket->sap,
+ param->user_param);
+ }
+
+ if (param->data.buffer)
+ g_free(param->data.buffer);
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_connect_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_llcp_msg->result,
+ NULL,
+ NULL,
+ param->user_param);
+ }
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_disconnect_thread_func(gpointer user_data)
+{
+ ServerLlcpData *data;
+
+ net_nfc_request_llcp_msg_t *req_llcp_msg;
+ net_nfc_llcp_param_t *param;
+
+ data = (ServerLlcpData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerLlcpData");
+
+ return;
+ }
+
+ if (data->llcp == NULL)
+ {
+ DEBUG_ERR_MSG("can not get llcp");
+
+ g_free(data->req_msg);
+ g_free(data);
+
+ return;
+ }
+
+ if (data->req_msg == NULL)
+ {
+ DEBUG_ERR_MSG("can not get request msg");
+
+ g_object_unref(data->llcp);
+ g_free(data);
+
+ return;
+ }
+
+ req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
+ param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+
+ if (param)
+ {
+ if (param->cb)
+ {
+ param->cb(param->socket,
+ req_llcp_msg->result,
+ NULL,
+ NULL,
+ param->user_param);
+ }
+
+ g_free(param);
+ }
+
+ g_object_unref(data->llcp);
+
+ g_free(data->req_msg);
+ g_free(data);
+}
+
+static void llcp_simple_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (simple_data->error_callback)
+ {
+ simple_data->error_callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_listen_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("listen socket failed, [%d]", result);
+ }
+
+ if (simple_data->callback)
+ {
+ simple_data->callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_connect_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("connect socket failed, [%d]", result);
+ }
+
+ if (simple_data->callback)
+ {
+ simple_data->callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_server_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (simple_data->error_callback)
+ {
+ simple_data->error_callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_send_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (simple_data->callback)
+ {
+ simple_data->callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+static void llcp_simple_receive_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ LlcpSimpleData *simple_data;
+
+ simple_data = (LlcpSimpleData *)user_param;
+
+ if (simple_data->callback)
+ {
+ simple_data->callback(result,
+ simple_data->handle,
+ socket,
+ data,
+ simple_data->user_data);
+ }
+
+ g_free(simple_data);
+}
+
+/* Public Function */
+gboolean net_nfc_server_llcp_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (llcp_skeleton)
+ g_object_unref(llcp_skeleton);
+
+ llcp_skeleton = net_nfc_gdbus_llcp_skeleton_new();
+
+ g_signal_connect(llcp_skeleton,
+ "handle-config",
+ G_CALLBACK(llcp_handle_config),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-listen",
+ G_CALLBACK(llcp_handle_listen),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-connect",
+ G_CALLBACK(llcp_handle_connect),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-connect-sap",
+ G_CALLBACK(llcp_handle_connect_sap),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-send",
+ G_CALLBACK(llcp_handle_send),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-send-to",
+ G_CALLBACK(llcp_handle_send_to),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-receive",
+ G_CALLBACK(llcp_handle_receive),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-receive-from",
+ G_CALLBACK(llcp_handle_receive_from),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-close",
+ G_CALLBACK(llcp_handle_close),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-disconnect",
+ G_CALLBACK(llcp_handle_disconnect),
+ NULL);
+
+ if(g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(llcp_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Llcp",
+ &error) == FALSE)
+ {
+ g_error_free(error);
+ g_object_unref(llcp_skeleton);
+ llcp_skeleton = NULL;
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_llcp_deinit(void)
+{
+ if (llcp_skeleton)
+ {
+ g_object_unref(llcp_skeleton);
+ llcp_skeleton = NULL;
+ }
+}
+
+void net_nfc_server_llcp_deactivated(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_deactivated_thread_func);
+}
+
+void net_nfc_server_llcp_listen(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_listen_thread_func);
+}
+
+void net_nfc_server_llcp_socket_error(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_socket_error_thread_func);
+}
+
+void net_nfc_server_llcp_send(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_send_thread_func);
+}
+
+void net_nfc_server_llcp_receive(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_receive_thread_func);
+}
+
+void net_nfc_server_llcp_receive_from(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_receive_from_thread_func);
+}
+
+void net_nfc_server_llcp_connect(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_connect_thread_func);
+}
+
+void net_nfc_server_llcp_disconnect(net_nfc_request_msg_t *req_msg)
+{
+ llcp_add_async_queue(req_msg, llcp_disconnect_thread_func);
+}
+
+net_nfc_error_e net_nfc_server_llcp_set_config(
+ net_nfc_llcp_config_info_s *config)
+{
+ net_nfc_error_e result;
+
+ if (config == NULL)
+ {
+ net_nfc_controller_llcp_config(&llcp_config, &result);
+ return result;
+ }
+
+ net_nfc_controller_llcp_config(config, &result);
+ memcpy(&llcp_config, config, sizeof(llcp_config));
+
+ return result;
+}
+
+guint16 net_nfc_server_llcp_get_miu(void)
+{
+ return llcp_config.miu;
+}
+
+guint16 net_nfc_server_llcp_get_wks(void)
+{
+ return llcp_config.wks;
+}
+
+guint8 net_nfc_server_llcp_get_lto(void)
+{
+ return llcp_config.lto;
+}
+
+guint8 net_nfc_server_llcp_get_option(void)
+{
+ return llcp_config.option;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_server(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_llcp_callback callback,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_llcp_config_info_s config;
+
+ LlcpSimpleData *simple_data = NULL;
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (san == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_controller_llcp_get_remote_config(handle,
+ &config,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_get_remote_config",
+ result);
+ return result;
+ }
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+ if(simple_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ simple_data->handle = handle;
+ simple_data->callback = callback;
+ simple_data->error_callback = error_callback;
+ simple_data->user_data = user_data;
+
+ simple_data->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED,
+ simple_data->miu,
+ 1,
+ &result,
+ llcp_simple_socket_error_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_create_socket",
+ result);
+
+ g_free(simple_data);
+ return result;
+ }
+
+ simple_data->socket = socket;
+
+ if (net_nfc_controller_llcp_bind(socket,
+ sap,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "nte_nfc_controller_llcp_bind",
+ result);
+
+ if (simple_data->socket != 1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ g_free(simple_data);
+
+ return result;
+ }
+
+ if (net_nfc_controller_llcp_listen(handle,
+ (uint8_t *)san,
+ socket,
+ &result,
+ llcp_simple_listen_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_listen",
+ result);
+
+ if (simple_data->socket != 1)
+ {
+ net_nfc_controller_llcp_socket_close(
+ simple_data->socket,
+ &result);
+ }
+
+ g_free(simple_data);
+
+ return result;
+
+ }
+
+ DEBUG_SERVER_MSG("result [%d]", result);
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_client(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_llcp_callback callback,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_llcp_config_info_s config;
+
+ LlcpSimpleData *simple_data = NULL;
+
+ if (handle == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ if (net_nfc_controller_llcp_get_remote_config(handle,
+ &config,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_get_remote_config",
+ result);
+ return result;
+ }
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+
+ simple_data->handle = handle;
+ simple_data->callback = callback;
+ simple_data->error_callback = error_callback;
+ simple_data->user_data = user_data;
+
+ simple_data->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
+
+ if (net_nfc_controller_llcp_create_socket(&socket,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED,
+ simple_data->miu,
+ 1,
+ &result,
+ llcp_simple_socket_error_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_create_socket",
+ result);
+
+ g_free(simple_data);
+ return result;
+ }
+
+ simple_data->socket = socket;
+
+ if (san == NULL)
+ {
+ if (net_nfc_controller_llcp_connect(handle,
+ simple_data->socket,
+ sap,
+ &result,
+ llcp_simple_connect_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_connect",
+ result);
+
+ if (simple_data->socket != -1)
+ {
+ net_nfc_controller_llcp_socket_close(
+ simple_data->socket,
+ &result);
+ }
+
+ g_free(simple_data);
+
+ return result;
+ }
+
+ }
+ else
+ {
+ if (net_nfc_controller_llcp_connect_by_url(handle,
+ simple_data->socket,
+ (uint8_t *)san,
+ &result,
+ llcp_simple_connect_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_connect_by_url",
+ result);
+
+ if (simple_data->socket != -1)
+ {
+ net_nfc_controller_llcp_socket_close(
+ simple_data->socket,
+ &result);
+ }
+
+ g_free(simple_data);
+
+ return result;
+ }
+ }
+
+ DEBUG_SERVER_MSG("result [%d]", result);
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_accept(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_server_llcp_callback error_callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ LlcpSimpleData *simple_data;
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+ if(simple_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->error_callback = error_callback;
+ simple_data->user_data = user_data;
+
+ if (net_nfc_controller_llcp_accept(socket,
+ &result,
+ llcp_simple_server_error_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_accept",
+ result);
+ }
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_send(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ net_nfc_server_llcp_callback callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ LlcpSimpleData *simple_data;
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+ if(simple_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->callback = callback;
+ simple_data->user_data = user_data;
+
+ if (net_nfc_controller_llcp_send(handle,
+ socket,
+ data,
+ &result,
+ llcp_simple_send_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_send",
+ result);
+ }
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_simple_receive(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_server_llcp_callback callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ LlcpSimpleData *simple_data;
+
+ simple_data = g_new0(LlcpSimpleData, 1);
+ if(simple_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->callback = callback;
+ simple_data->user_data = user_data;
+
+ if (net_nfc_controller_llcp_recv(handle,
+ socket,
+ net_nfc_server_llcp_get_miu(),
+ &result,
+ llcp_simple_receive_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_send",
+ result);
+ }
+
+ if (result == NET_NFC_BUSY)
+ result = NET_NFC_OK;
+
+ return result;
+}
+
+typedef struct _service_t
+{
+ uint32_t sap;
+ char *san;
+ char *id;
+ net_nfc_server_llcp_activate_cb cb;
+ void *user_data;
+}
+service_t;
+
+static GHashTable *service_table;
+
+static void _llcp_init()
+{
+ if (service_table == NULL)
+ service_table = g_hash_table_new(NULL, NULL);
+}
+
+inline static service_t *_llcp_find_service(uint32_t sap)
+{
+ return (service_t *)g_hash_table_lookup(service_table,
+ (gconstpointer)sap);
+}
+
+static net_nfc_error_e _llcp_add_service(const char *id, uint32_t sap,
+ const char *san, net_nfc_server_llcp_activate_cb cb, void *user_data)
+{
+ service_t *service = NULL;
+ net_nfc_error_e result;
+
+ if (cb == NULL) {
+ DEBUG_ERR_MSG("callback is mandatory");
+
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _llcp_init();
+
+ if (_llcp_find_service(sap) == NULL) {
+ DEBUG_SERVER_MSG("new service, sap [%d]", sap);
+
+ service = g_new0(service_t, 1);
+ if (service != NULL) {
+ service->sap = sap;
+ if (san != NULL && strlen(san) > 0) {
+ service->san = g_strdup(san);
+ }
+ if (id != NULL && strlen(id) > 0) {
+ service->id = g_strdup(id);
+ }
+ service->cb = cb;
+ service->user_data = user_data;
+
+ g_hash_table_insert(service_table, (gpointer)sap,
+ (gpointer)service);
+
+ result = NET_NFC_OK;
+ } else {
+ DEBUG_ERR_MSG("alloc failed");
+
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ DEBUG_ERR_MSG("already registered");
+
+ result = NET_NFC_ALREADY_REGISTERED;
+ }
+
+ return result;
+}
+
+static void _llcp_remove_service(uint32_t sap)
+{
+ service_t *service = NULL;
+
+ service = _llcp_find_service(sap);
+ if (service != NULL) {
+ g_free(service->san);
+ g_free(service->id);
+ g_free(service);
+
+ g_hash_table_remove(service_table, (gconstpointer)sap);
+ }
+}
+
+static void _llcp_remove_services(const char *id)
+{
+ GHashTableIter iter;
+ gpointer key;
+ service_t *service;
+
+ if (service_table == NULL)
+ return;
+
+ g_hash_table_iter_init (&iter, service_table);
+
+ while (g_hash_table_iter_next (&iter, &key, (gpointer)&service)) {
+ if (id == NULL || strcmp(service->id, id) == 0) {
+ g_free(service->san);
+ g_free(service->id);
+ g_free(service);
+
+ g_hash_table_iter_remove(&iter);
+ }
+ }
+}
+
+static void _llcp_start_services_cb(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ service_t *service = (service_t *)value;
+
+ /* TODO : start service */
+ if (service != NULL && service->cb != NULL) {
+ service->cb(NET_NFC_LLCP_START,
+ (net_nfc_target_handle_s *)user_data,
+ service->sap,
+ service->san, service->user_data);
+ }
+}
+
+static void _llcp_start_services(net_nfc_target_handle_s *handle)
+{
+ g_hash_table_foreach(service_table, _llcp_start_services_cb, handle);
+}
+
+net_nfc_error_e net_nfc_server_llcp_register_service(const char *id,
+ sap_t sap, const char *san, net_nfc_server_llcp_activate_cb cb,
+ void *user_param)
+{
+ return _llcp_add_service(id, sap, san, cb, user_param);
+}
+
+net_nfc_error_e net_nfc_server_llcp_unregister_service(const char *id,
+ sap_t sap, const char *san)
+{
+ net_nfc_error_e result;
+ service_t *service;
+
+ service = _llcp_find_service(sap);
+ if (service != NULL) {
+ /* invoke callback */
+ service->cb(NET_NFC_LLCP_UNREGISTERED, NULL, service->sap,
+ service->san, service->user_data);
+
+ _llcp_remove_service(sap);
+
+ result = NET_NFC_OK;
+ } else {
+ DEBUG_ERR_MSG("service is not registered");
+
+ result = NET_NFC_NOT_REGISTERED;
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_llcp_unregister_services(const char *id)
+{
+ _llcp_remove_services(id);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_server_llcp_unregister_all()
+{
+ GHashTableIter iter;
+ gpointer key;
+ service_t *service;
+
+ if (service_table == NULL)
+ return NET_NFC_OK;
+
+ g_hash_table_iter_init(&iter, service_table);
+
+ while (g_hash_table_iter_next(&iter, &key, (gpointer)&service)) {
+ service->cb(NET_NFC_LLCP_UNREGISTERED, NULL, service->sap,
+ service->san, service->user_data);
+
+ g_free(service->san);
+ g_free(service->id);
+ g_free(service);
+
+ g_hash_table_iter_remove(&iter);
+ }
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_server_llcp_start_registered_services(
+ net_nfc_target_handle_s *handle)
+{
+ _llcp_start_services(handle);
+
+ return NET_NFC_OK;
+}
+
+static void net_nfc_server_llcp_process(gpointer user_data)
+{
+ net_nfc_current_target_info_s *target;
+#if 0
+ net_nfc_error_e result;
+#endif
+ net_nfc_target_handle_s *handle;
+ net_nfc_target_type_e dev_type;
+
+ target = net_nfc_server_get_target_info();
+
+ g_assert(target != NULL); /* raise exception!!! what;s wrong?? */
+
+ handle = target->handle;
+ dev_type = target->devType;
+
+ DEBUG_SERVER_MSG("connection type = [%d]", handle->connection_type);
+#if 0
+ if (dev_type == NET_NFC_NFCIP1_TARGET)
+ {
+ DEBUG_SERVER_MSG("LLCP : target, try to connect");
+
+ if (net_nfc_controller_connect(handle, &result) == false)
+ {
+ DEBUG_SERVER_MSG("%s is failed, [%d]",
+ "net_nfc_controller_connect",
+ result);
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_RESUME,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed [%d]",
+ "net_nfc_controller_configure_discovery",
+ result);
+
+ net_nfc_controller_exception_handler();
+ }
+
+ return;
+ }
+ }
+
+ DEBUG_SERVER_MSG("check LLCP");
+
+ if (net_nfc_controller_llcp_check_llcp(handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed [%d]",
+ "net_nfc_controller_llcp_check_llcp",
+ result);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("activate LLCP");
+
+ if (net_nfc_controller_llcp_activate_llcp(handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed [%d]",
+ "net_nfc_controller_llcp_activate_llcp",
+ result);
+
+ return;
+ }
+#endif
+ net_nfc_server_llcp_start_registered_services(handle);
+
+ net_nfc_server_p2p_discovered(handle);
+}
+
+void net_nfc_server_llcp_target_detected(void *info)
+{
+ if (net_nfc_server_controller_async_queue_push(
+ net_nfc_server_llcp_process, NULL) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not push to controller thread");
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vconf.h>
+
+#include "net_nfc_typedef.h"
+
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_manager.h"
+#include "net_nfc_server_tag.h"
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_manager.h"
+#include "net_nfc_server_se.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_server_process_npp.h"
+#include "net_nfc_server_process_handover.h"
+#include "net_nfc_server_context_internal.h"
+
+typedef struct _ManagerData ManagerData;
+
+struct _ManagerData
+{
+ NetNfcGDbusManager *manager;
+ GDBusMethodInvocation *invocation;
+};
+
+typedef struct _ManagerActivationData ManagerActivationData;
+
+struct _ManagerActivationData
+{
+ NetNfcGDbusManager *manager;
+ GDBusMethodInvocation *invocation;
+ gboolean is_active;
+};
+
+typedef struct _ManagerPrbsData ManagerPrbsData;
+
+struct _ManagerPrbsData
+{
+ NetNfcGDbusManager *manager;
+ GDBusMethodInvocation *invocation;
+ guint32 tech;
+ guint32 rate;
+};
+
+typedef struct _ServerManagerActivationData ServerManagerActivationData;
+
+struct _ServerManagerActivationData
+{
+ NetNfcGDbusManager *manager;
+ gboolean is_active;
+};
+
+
+static NetNfcGDbusManager *manager_skeleton = NULL;
+
+static gboolean manager_active(void);
+
+static gboolean manager_deactive(void);
+
+static void manager_handle_active_thread_func(gpointer user_data);
+
+static gboolean manager_handle_set_active(NetNfcGDbusManager *manager,
+ GDBusMethodInvocation *invocation,
+ gboolean arg_is_active,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+static void manager_active_thread_func(gpointer user_data);
+
+
+/* reimplementation of net_nfc_service_init()*/
+static gboolean manager_active(void)
+{
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_is_ready(&result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_cotroller_is_ready", result);
+ return FALSE;
+ }
+
+ result = net_nfc_server_se_change_se(SECURE_ELEMENT_TYPE_UICC);
+
+ /* register default snep server */
+ net_nfc_server_snep_default_server_register();
+
+ /* register default npp server */
+ net_nfc_server_npp_default_server_register();
+
+ /* register default handover server */
+ net_nfc_server_handover_default_server_register();
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_START,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed %d",
+ "net_nfc_controller_configure_discovery",
+ result);
+ return FALSE;
+ }
+
+ /* vconf on */
+ if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0)
+ {
+ DEBUG_ERR_MSG("%s is failed", "vconf_set_bool");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* reimplementation of net_nfc_service_deinit()*/
+static gboolean manager_deactive(void)
+{
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_is_ready(&result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_cotroller_is_ready", result);
+ return FALSE;
+ }
+
+ /* unregister all services */
+ net_nfc_server_llcp_unregister_all();
+
+ result = net_nfc_server_se_change_se(SECURE_ELEMENT_TYPE_INVALID);
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_STOP,
+ NET_NFC_ALL_DISABLE,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s is failed %d",
+ "net_nfc_controller_configure_discovery",
+ result);
+ return FALSE;
+ }
+
+ /* vconf off */
+ if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0)
+ {
+ DEBUG_ERR_MSG("%s is failed", "vconf_set_bool");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void manager_handle_active_thread_func(gpointer user_data)
+{
+ gboolean ret;
+
+ ManagerActivationData *data;
+
+ data = (ManagerActivationData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ManagerActivationData");
+ return;
+ }
+
+ if (data->is_active)
+ ret = manager_active();
+ else
+ ret = manager_deactive();
+
+ if (data->manager == NULL)
+ {
+ DEBUG_ERR_MSG("can not get manager");
+
+ if(data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SetActiveError",
+ "Can not get manager");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_free(data);
+ return;
+ }
+
+ if (ret == FALSE)
+ {
+ if (data->invocation)
+ {
+ g_dbus_method_invocation_return_dbus_error(
+ data->invocation,
+ "org.tizen.NetNfcService.SetActiveError",
+ "Can not set activation");
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->manager);
+ g_free(data);
+
+ return;
+ }
+
+ net_nfc_gdbus_manager_emit_activated(data->manager,
+ data->is_active);
+
+ if (data->invocation)
+ {
+ net_nfc_gdbus_manager_complete_set_active(data->manager,
+ data->invocation);
+
+ g_object_unref(data->invocation);
+ }
+
+ g_object_unref(data->manager);
+ g_free(data);
+
+ /* shutdown process if it doesn't need */
+ if (data->is_active == false &&
+ net_nfc_server_gdbus_is_server_busy() == false) {
+
+ net_nfc_manager_quit();
+ }
+}
+
+
+static gboolean manager_handle_set_active(NetNfcGDbusManager *manager,
+ GDBusMethodInvocation *invocation,
+ gboolean arg_is_active,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ ManagerActivationData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::admin",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ DEBUG_SERVER_MSG("is_active %d", arg_is_active);
+
+ data = g_new0(ManagerActivationData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+ return FALSE;
+ }
+
+ data->manager = g_object_ref(manager);
+ data->invocation = g_object_ref(invocation);
+ data->is_active = arg_is_active;
+
+ if (net_nfc_server_controller_async_queue_push(
+ manager_handle_active_thread_func,
+ data) == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+ if (data)
+ {
+ g_object_unref(data->manager);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+ return FALSE;
+ }
+
+ if (arg_is_active)
+ net_nfc_server_restart_polling_loop();
+
+ return TRUE;
+}
+
+static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ guint32 state;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::admin",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ state = net_nfc_server_get_state();
+
+ net_nfc_gdbus_manager_complete_get_server_state(manager,
+ invocation,
+ state);
+ return TRUE;
+}
+
+/* server side */
+static void manager_active_thread_func(gpointer user_data)
+{
+ ServerManagerActivationData *data;
+
+ gboolean ret = FALSE;
+
+ data = (ServerManagerActivationData *)user_data;
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("can not get ServerManagerActivationData");
+ return;
+ }
+
+ if (data->is_active)
+ ret = manager_active();
+ else
+ ret = manager_deactive();
+
+ if (ret == FALSE)
+ {
+ DEBUG_ERR_MSG("can not set activation");
+ g_free(data);
+ return;
+ }
+
+ net_nfc_gdbus_manager_emit_activated(data->manager,
+ data->is_active);
+
+ g_free(data);
+}
+
+gboolean net_nfc_server_manager_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (manager_skeleton)
+ g_object_unref(manager_skeleton);
+
+ manager_skeleton = net_nfc_gdbus_manager_skeleton_new();
+
+ g_signal_connect(manager_skeleton,
+ "handle-set-active",
+ G_CALLBACK(manager_handle_set_active),
+ NULL);
+
+ g_signal_connect(manager_skeleton,
+ "handle-get-server-state",
+ G_CALLBACK(manager_handle_get_server_state),
+ NULL);
+
+ if (g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(manager_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Manager",
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
+
+ g_error_free(error);
+ g_object_unref(manager_skeleton);
+
+ manager_skeleton = NULL;
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_manager_deinit(void)
+{
+ if (manager_skeleton)
+ {
+ g_object_unref(manager_skeleton);
+ manager_skeleton = NULL;
+ }
+}
+
+void net_nfc_server_manager_set_active(gboolean is_active)
+{
+ ServerManagerActivationData *data;
+
+ if (manager_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("%s is not initialized",
+ "net_nfc_server_manager");
+ return;
+ }
+
+ DEBUG_SERVER_MSG("is_active %d", is_active);
+
+ data = g_new0(ServerManagerActivationData, 1);
+
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ return;
+ }
+
+ data->manager = g_object_ref(manager_skeleton);
+ data->is_active = is_active;
+
+ if (net_nfc_server_controller_async_queue_push(
+ manager_active_thread_func,
+ data) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not push to controller thread");
+
+ if (data)
+ {
+ g_object_unref(data->manager);
+
+ g_free(data);
+ }
+ }
+
+ if (is_active)
+ net_nfc_server_restart_polling_loop();
+
+ return;
+}
+
+bool net_nfc_server_manager_get_active()
+{
+ int value;
+
+ if (vconf_get_bool(VCONFKEY_NFC_STATE, &value) < 0)
+ return false;
+
+ return (!!value);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_gdbus.h"
+
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context_internal.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_ndef.h"
+
+typedef struct _ReadData ReadData;
+
+struct _ReadData
+{
+ NetNfcGDbusNdef *ndef;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+};
+
+typedef struct _WriteData WriteData;
+
+struct _WriteData
+{
+ NetNfcGDbusNdef *ndef;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+ data_s data;
+};
+
+typedef struct _MakeReadOnlyData MakeReadOnlyData;
+
+struct _MakeReadOnlyData
+{
+ NetNfcGDbusNdef *ndef;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+};
+
+typedef struct _FormatData FormatData;
+
+struct _FormatData
+{
+ NetNfcGDbusNdef *ndef;
+ GDBusMethodInvocation *invocation;
+ guint32 handle;
+ data_s key;
+};
+
+
+static NetNfcGDbusNdef *ndef_skeleton = NULL;
+
+static void ndef_read_thread_func(gpointer user_data);
+
+static void ndef_write_thread_func(gpointer user_data);
+
+static void ndef_make_read_only_thread_func(gpointer user_data);
+
+static void ndef_format_thread_func(gpointer user_data);
+
+/* methods */
+static gboolean ndef_handle_read(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean ndef_handle_write(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean ndef_handle_make_read_only(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean ndef_handle_format(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *arg_key,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+static void ndef_read_thread_func(gpointer user_data)
+{
+ ReadData *data = user_data;
+
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ data_s *read_data = NULL;
+ GVariant *data_variant;
+
+ g_assert(data != NULL);
+ g_assert(data->ndef != NULL);
+ g_assert(data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(data->handle);
+
+ if (net_nfc_server_target_connected(handle) == true) {
+ net_nfc_controller_read_ndef(handle, &read_data, &result);
+ } else {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ data_variant = net_nfc_util_gdbus_data_to_variant(read_data);
+
+ net_nfc_gdbus_ndef_complete_read(data->ndef,
+ data->invocation,
+ (gint)result,
+ data_variant);
+
+ if (read_data) {
+ net_nfc_util_free_data(read_data);
+ g_free(read_data);
+ }
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+}
+
+static void ndef_write_thread_func(gpointer user_data)
+{
+ WriteData *data = user_data;
+
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+
+ g_assert(data != NULL);
+ g_assert(data->ndef != NULL);
+ g_assert(data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(data->handle);
+
+ if (net_nfc_server_target_connected(handle) == true) {
+ net_nfc_controller_write_ndef(handle, &data->data, &result);
+ } else {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ net_nfc_gdbus_ndef_complete_write(data->ndef,
+ data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+}
+
+static void ndef_make_read_only_thread_func(gpointer user_data)
+{
+ MakeReadOnlyData *data = user_data;
+
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+
+ g_assert(data != NULL);
+ g_assert(data->ndef != NULL);
+ g_assert(data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(data->handle);
+
+ if (net_nfc_server_target_connected(handle) == true) {
+ net_nfc_controller_make_read_only_ndef(handle, &result);
+ } else {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ net_nfc_gdbus_ndef_complete_make_read_only(data->ndef,
+ data->invocation,
+ (gint)result);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+}
+
+static void ndef_format_thread_func(gpointer user_data)
+{
+ FormatData *data = user_data;
+
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+
+ g_assert(data != NULL);
+ g_assert(data->ndef != NULL);
+ g_assert(data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(data->handle);
+
+ if (net_nfc_server_target_connected(handle) == true) {
+ net_nfc_controller_format_ndef(handle, &data->key, &result);
+ } else {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ net_nfc_gdbus_ndef_complete_format(data->ndef,
+ data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&data->key);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+}
+
+static gboolean ndef_handle_read(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ ReadData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(ReadData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->ndef = g_object_ref(ndef);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+
+ result = net_nfc_server_controller_async_queue_push(
+ ndef_read_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Ndef.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean ndef_handle_write(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ WriteData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(WriteData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->ndef = g_object_ref(ndef);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ ndef_write_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Ndef.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean ndef_handle_make_read_only(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ MakeReadOnlyData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(MakeReadOnlyData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->ndef = g_object_ref(ndef);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+
+ result = net_nfc_server_controller_async_queue_push(
+ ndef_make_read_only_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Ndef.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean ndef_handle_format(NetNfcGDbusNdef *ndef,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ GVariant *arg_key,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ FormatData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(FormatData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->ndef = g_object_ref(ndef);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ net_nfc_util_gdbus_variant_to_data_s(arg_key, &data->key);
+
+ result = net_nfc_server_controller_async_queue_push(
+ ndef_format_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Ndef.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->key);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->ndef);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+gboolean net_nfc_server_ndef_init(GDBusConnection *connection)
+{
+ gboolean result;
+ GError *error = NULL;
+
+ if (ndef_skeleton)
+ net_nfc_server_ndef_deinit();
+
+ ndef_skeleton = net_nfc_gdbus_ndef_skeleton_new();
+
+ g_signal_connect(ndef_skeleton,
+ "handle-read",
+ G_CALLBACK(ndef_handle_read),
+ NULL);
+
+ g_signal_connect(ndef_skeleton,
+ "handle-write",
+ G_CALLBACK(ndef_handle_write),
+ NULL);
+
+ g_signal_connect(ndef_skeleton,
+ "handle-make-read-only",
+ G_CALLBACK(ndef_handle_make_read_only),
+ NULL);
+
+ g_signal_connect(ndef_skeleton,
+ "handle-format",
+ G_CALLBACK(ndef_handle_format),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(ndef_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Ndef",
+ &error);
+ if (result == FALSE)
+ {
+ g_error_free(error);
+
+ net_nfc_server_ndef_deinit();
+ }
+
+ return TRUE;
+}
+
+void net_nfc_server_ndef_deinit(void)
+{
+ if (ndef_skeleton)
+ {
+ g_object_unref(ndef_skeleton);
+ ndef_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context_internal.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_server_p2p.h"
+
+
+typedef struct _P2pSendData P2pSendData;
+
+struct _P2pSendData
+{
+ NetNfcGDbusP2p *p2p;
+ GDBusMethodInvocation *invocation;
+ gint32 type;
+ guint32 p2p_handle;
+ data_s data;
+};
+
+static void p2p_send_data_thread_func(gpointer user_data);
+
+static gboolean p2p_handle_send(NetNfcGDbusP2p *p2p,
+ GDBusMethodInvocation *invocation,
+ gint32 arg_type,
+ GVariant *arg_data,
+ guint32 handle,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static NetNfcGDbusP2p *p2p_skeleton = NULL;
+
+static void p2p_send_data_thread_func(gpointer user_data)
+{
+ P2pSendData *p2p_data = (P2pSendData *)user_data;
+ net_nfc_error_e result;
+ net_nfc_target_handle_s *handle;
+
+ g_assert(p2p_data != NULL);
+ g_assert(p2p_data->p2p != NULL);
+ g_assert(p2p_data->invocation != NULL);
+
+ handle = GUINT_TO_POINTER(p2p_data->p2p_handle);
+
+ result = net_nfc_server_snep_default_client_start(
+ GUINT_TO_POINTER(p2p_data->p2p_handle),
+ SNEP_REQ_PUT,
+ &p2p_data->data,
+ -1,
+ p2p_data);
+ if (result != NET_NFC_OK)
+ {
+ net_nfc_gdbus_p2p_complete_send(p2p_data->p2p,
+ p2p_data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&p2p_data->data);
+
+ g_object_unref(p2p_data->invocation);
+ g_object_unref(p2p_data->p2p);
+
+ g_free(p2p_data);
+ }
+}
+
+static gboolean p2p_handle_send(NetNfcGDbusP2p *p2p,
+ GDBusMethodInvocation *invocation,
+ gint32 arg_type,
+ GVariant *arg_data,
+ guint32 handle,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ gboolean result;
+ P2pSendData *data;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(P2pSendData, 1);
+ if(data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->p2p = g_object_ref(p2p);
+ data->invocation = g_object_ref(invocation);
+ data->type = arg_type;
+ data->p2p_handle = handle;
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ p2p_send_data_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.P2p.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->p2p);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+
+gboolean net_nfc_server_p2p_init(GDBusConnection *connection)
+{
+ gboolean result;
+ GError *error = NULL;
+
+ if (p2p_skeleton)
+ net_nfc_server_p2p_deinit();
+
+ p2p_skeleton = net_nfc_gdbus_p2p_skeleton_new();
+
+ g_signal_connect(p2p_skeleton,
+ "handle-send",
+ G_CALLBACK(p2p_handle_send),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(p2p_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/P2p",
+ &error);
+ if (result == FALSE)
+ {
+ g_error_free(error);
+
+ net_nfc_server_p2p_deinit();
+ }
+
+ return result;
+}
+
+void net_nfc_server_p2p_deinit(void)
+{
+ if (p2p_skeleton)
+ {
+ g_object_unref(p2p_skeleton);
+ p2p_skeleton = NULL;
+ }
+}
+
+void net_nfc_server_p2p_detached(void)
+{
+ if (p2p_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_skeleton is not initialized");
+
+ return;
+ }
+
+ DEBUG_ERR_MSG("p2p detached signal");
+
+ net_nfc_gdbus_p2p_emit_detached(p2p_skeleton);
+}
+
+void net_nfc_server_p2p_discovered(net_nfc_target_handle_h handle)
+{
+ if (p2p_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_skeleton is not initialized");
+
+ return;
+ }
+
+ DEBUG_ERR_MSG("Emitting p2p discovered signal");
+
+ net_nfc_gdbus_p2p_emit_discovered(p2p_skeleton,
+ GPOINTER_TO_UINT(handle));
+}
+
+void net_nfc_server_p2p_received(data_h user_data)
+{
+ GVariant *arg_data;
+
+ if (p2p_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("p2p_skeleton is not initialized");
+
+ return;
+ }
+
+ arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)user_data);
+
+ net_nfc_gdbus_p2p_emit_received(p2p_skeleton, arg_data);
+}
+
+void net_nfc_server_p2p_data_sent(net_nfc_error_e result,
+ gpointer user_data)
+{
+ P2pSendData *data = (P2pSendData *)user_data;
+
+ g_assert(data != NULL);
+ g_assert(data->p2p != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_gdbus_p2p_complete_send(data->p2p,
+ data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->p2p);
+
+ g_free(data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "bluetooth-api.h"
+#include "net_nfc_server_handover.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+#include "net_nfc_util_handover.h"
+#include "net_nfc_manager_util_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_handover_internal.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_util_gdbus_internal.h"
+
+
+typedef void (*_net_nfc_server_handover_create_carrier_msg_cb)(
+ net_nfc_error_e result,
+ ndef_message_s *selector,
+ void *user_param);
+
+typedef struct _net_nfc_handover_context_t
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t socket;
+ uint32_t state;
+ net_nfc_conn_handover_carrier_type_e type;
+ data_s data;
+ ndef_record_s *record;
+ void *user_param;
+}
+net_nfc_handover_context_t;
+
+#define NET_NFC_CH_CONTEXT net_nfc_target_handle_s *handle;\
+ net_nfc_llcp_socket_t socket;\
+ net_nfc_error_e result;\
+ int step;\
+ net_nfc_conn_handover_carrier_type_e type;\
+ void *user_param;
+
+typedef struct _net_nfc_server_handover_create_config_context_t
+{
+ NET_NFC_CH_CONTEXT;
+
+ _net_nfc_server_handover_create_carrier_msg_cb cb;
+ net_nfc_conn_handover_carrier_type_e current_type;
+ ndef_message_s *ndef_message;
+ ndef_message_s *requester; /* for low power selector */
+
+ ndef_record_s *record;
+}
+net_nfc_server_handover_create_config_context_t;
+
+typedef struct _net_nfc_server_handover_process_config_context_t
+{
+ NET_NFC_CH_CONTEXT;
+
+ net_nfc_server_handover_process_carrier_record_cb cb;
+}
+net_nfc_server_handover_process_config_context_t;
+
+
+
+static void _net_nfc_server_handover_send_response(void *user_param,
+ data_h ac_data,
+ net_nfc_error_e result);
+
+static void _net_nfc_server_handover_client_process(
+ net_nfc_handover_context_t *context);
+
+static void _net_nfc_server_handover_client_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param);
+
+static void _net_nfc_server_handover_client_connected_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param);
+
+static void _net_nfc_server_handover_get_response_process(
+ net_nfc_handover_context_t *context);
+
+static net_nfc_error_e _net_nfc_server_handover_process_carrier_record(
+ ndef_record_s *carrier,
+ void *cb,
+ void *user_param);
+
+static int _net_nfc_server_handover_append_wifi_carrier_config(
+ net_nfc_server_handover_create_config_context_t *context);
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_requester_from_rawdata(
+ ndef_message_s **requestor,
+ data_s *data);
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_requester_carrier_configs(
+ net_nfc_conn_handover_carrier_type_e type,
+ void *cb,
+ void *user_param);
+
+static bool _net_nfc_server_handover_check_hr_record_validation(
+ ndef_message_s *message);
+
+static bool _net_nfc_server_handover_check_hs_record_validation(
+ ndef_message_s *message);
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_selector_carrier_configs(
+ net_nfc_conn_handover_carrier_type_e type,
+ void *cb,
+ void *user_param);
+
+static int _net_nfc_server_handover_iterate_create_carrier_configs(
+ net_nfc_server_handover_create_config_context_t *context);
+
+static int _net_nfc_server_handover_iterate_carrier_configs_to_next(
+ net_nfc_server_handover_create_config_context_t *context);
+
+static int _net_nfc_server_handover_iterate_carrier_configs_step(
+ net_nfc_server_handover_create_config_context_t *context);
+
+static void _net_nfc_server_handover_server_process(
+ net_nfc_handover_context_t *context);
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_low_power_selector_message(
+ ndef_message_s *request_msg,
+ ndef_message_s *select_msg);
+
+////////////////////////////////////////////////////////////////////////////
+
+static void _net_nfc_server_handover_send_response(
+ void *user_param,
+ data_h ac_data,
+ net_nfc_error_e result)
+{
+ HandoverRequestData *handover_data = NULL;
+ guint32 resp_event;
+ guint32 resp_type;
+ GVariant* data = NULL;
+
+ handover_data = (HandoverRequestData*)user_param;
+
+ data = net_nfc_util_gdbus_data_to_variant(ac_data);
+
+ resp_type = NET_NFC_MESSAGE_CONNECTION_HANDOVER;
+
+ if (result == NET_NFC_OK)
+ resp_event = NET_NFC_EXCHANGER_TRANSFER_COMPLETED;
+ else
+ resp_event = NET_NFC_EXCHANGER_TRANSFER_FAILED;
+
+ if (handover_data->invocation)
+ {
+ net_nfc_gdbus_handover_complete_request(
+ handover_data->handoverobj,
+ handover_data->invocation,
+ resp_event,
+ resp_type,
+ data);
+
+ g_object_unref(handover_data->invocation);
+ }
+
+ if (handover_data->data)
+ {
+ g_free(handover_data->data->buffer);
+ g_free(handover_data->data);
+ }
+
+ g_object_unref(handover_data->handoverobj);
+ g_free(handover_data);
+
+}
+
+static net_nfc_error_e _net_nfc_server_handover_convert_ndef_message_to_data(
+ ndef_message_s *msg,
+ data_s *data)
+{
+ net_nfc_error_e result;
+ uint32_t length;
+
+ if (msg == NULL || data == NULL)
+ {
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ length = net_nfc_util_get_ndef_message_length(msg);
+ if (length > 0)
+ {
+ net_nfc_util_alloc_data(data, length);
+ result = net_nfc_util_convert_ndef_message_to_rawdata(msg, data);
+ }
+ else
+ {
+ result = NET_NFC_INVALID_PARAM;
+ }
+
+ return result;
+}
+
+static void _net_nfc_server_handover_bt_get_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_state_e cps,
+ ndef_record_s *carrier,
+ uint32_t aux_data_count,
+ ndef_record_s *aux_data,
+ void *user_param)
+{
+ net_nfc_server_handover_create_config_context_t *context =
+ (net_nfc_server_handover_create_config_context_t *)user_param;
+
+ /* append record to ndef message */
+ if (result == NET_NFC_OK)
+ {
+ ndef_record_s *record;
+
+ /* FIXME : copy record and append */
+ net_nfc_util_create_record(carrier->TNF,
+ &carrier->type_s,
+ &carrier->id_s,
+ &carrier->payload_s,
+ &record);
+
+ if ((result = net_nfc_util_append_carrier_config_record(
+ context->ndef_message,
+ record,
+ cps)) == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("net_nfc_util_append_carrier"
+ "_config_record success");
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_append_carrier"
+ "_config_record failed [%d]",
+ result);
+ net_nfc_util_free_record(record);
+ }
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_to_next,
+ (gpointer)context);
+ }
+
+ /* don't free context */
+}
+
+static void _net_nfc_server_handover_bt_process_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_handover_process_config_context_t *context =
+ (net_nfc_server_handover_process_config_context_t *)user_param;
+
+ if (result == NET_NFC_OK)
+ {
+ if (context->cb != NULL)
+ {
+ context->cb(result, type, data, context->user_param);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_handover_bt_process_carrier_record failed [%d]",
+ result);
+ }
+
+ _net_nfc_util_free_mem(context);
+}
+
+
+static net_nfc_error_e
+_net_nfc_server_handover_get_carrier_record_by_priority_order(
+ ndef_message_s *request,
+ ndef_record_s **record)
+{
+ net_nfc_error_e result;
+ unsigned int carrier_count = 0;
+
+ LOGD("[%s] START", __func__);
+
+ if (request == NULL || record == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *record = NULL;
+
+ if ((result = net_nfc_util_get_alternative_carrier_record_count(
+ request,
+ &carrier_count)) == NET_NFC_OK)
+ {
+ int idx, priority;
+ net_nfc_conn_handover_carrier_type_e carrier_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ for (priority = NET_NFC_CONN_HANDOVER_CARRIER_BT;*record == NULL
+ && priority < NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;priority++)
+ {
+ /* check each carrier record and create matched record */
+ for (idx = 0; idx < carrier_count; idx++)
+ {
+ if ((net_nfc_util_get_alternative_carrier_type(
+ request,
+ idx,
+ &carrier_type)== NET_NFC_OK)
+ && (carrier_type == priority))
+ {
+ DEBUG_SERVER_MSG("selected carrier type"
+ " = [%d]", carrier_type);
+ net_nfc_util_get_carrier_config_record(
+ request,
+ idx,
+ record);
+ result = NET_NFC_OK;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier"
+ "_record_count failed");
+ }
+
+ LOGD("[%s] END", __func__);
+
+ return result;
+}
+
+static net_nfc_error_e _net_nfc_server_handover_create_requester_from_rawdata(
+ ndef_message_s **requestor,
+ data_s *data)
+{
+ net_nfc_error_e result;
+
+ if (requestor == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ *requestor = NULL;
+
+ result = net_nfc_util_create_ndef_message(requestor);
+ if (result == NET_NFC_OK)
+ {
+ result = net_nfc_util_convert_rawdata_to_ndef_message(data,
+ *requestor);
+
+ if (result == NET_NFC_OK)
+ {
+ if (_net_nfc_server_handover_check_hr_record_validation(
+ *requestor) == true)
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("record is not valid or"
+ " is not available");
+ net_nfc_util_free_ndef_message(*requestor);
+ result = NET_NFC_INVALID_PARAM;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef"
+ "failed [%d]",result);
+ }
+ } else {
+ DEBUG_ERR_MSG("net_nfc_util_create_ndef_message failed [%d]",
+ result);
+ }
+
+ return result;
+}
+
+static net_nfc_error_e _net_nfc_server_handover_create_selector_from_rawdata(
+ ndef_message_s **selector,
+ data_s *data)
+{
+ net_nfc_error_e result;
+
+ if (selector == NULL)
+ return NET_NFC_NULL_PARAMETER;
+
+ *selector = NULL;
+
+ if ((result = net_nfc_util_create_ndef_message(selector))
+ == NET_NFC_OK)
+ {
+ if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data,
+ *selector)) == NET_NFC_OK)
+ {
+
+ /* if record is not Hs record, then */
+ if (_net_nfc_server_handover_check_hs_record_validation(
+ *selector) == true)
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("record is not valid or is "
+ "not available");
+ net_nfc_util_free_ndef_message(*selector);
+ result = NET_NFC_INVALID_PARAM;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef"
+ " failed [%d]",result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message"
+ " failed [%d]",result);
+ }
+
+ return result;
+}
+
+static bool _net_nfc_server_handover_check_hr_record_validation(
+ ndef_message_s *message)
+{
+ unsigned int count;
+ ndef_record_s *rec;
+
+ LOGD("[%s] START", __func__);
+
+ if (message == NULL)
+ return false;
+
+ rec = (ndef_record_s *)message->records;
+
+ if (memcmp(rec->type_s.buffer, CH_REQ_RECORD_TYPE,
+ rec->type_s.length) != 0)
+ {
+ DEBUG_ERR_MSG("This is not connection handover"
+ " request message");
+ goto ERROR;
+ }
+
+ if (rec->payload_s.buffer[0] != CH_VERSION)
+ {
+ DEBUG_ERR_MSG("connection handover version is not matched");
+ goto ERROR;
+ }
+
+ if (net_nfc_util_get_alternative_carrier_record_count(message, &count)
+ != NET_NFC_OK || count == 0)
+ {
+ DEBUG_ERR_MSG("there is no carrier reference");
+ goto ERROR;
+ }
+
+ LOGD("[%s] END", __func__);
+
+ return true;
+
+ERROR :
+ LOGD("[%s] END", __func__);
+
+ return false;
+}
+
+static bool _net_nfc_server_handover_check_hs_record_validation(
+ ndef_message_s *message)
+{
+ unsigned int count;
+ ndef_record_s *rec;
+
+ LOGD("[%s] START", __func__);
+
+ if (message == NULL)
+ return false;
+
+ rec = (ndef_record_s *)message->records;
+
+ if (memcmp(rec->type_s.buffer, CH_SEL_RECORD_TYPE,
+ rec->type_s.length) != 0)
+ {
+ DEBUG_ERR_MSG("This is not connection handover"
+ " request message");
+ goto ERROR;
+ }
+
+ if (net_nfc_util_get_alternative_carrier_record_count(
+ message,&count)!= NET_NFC_OK || count == 0)
+ {
+ DEBUG_ERR_MSG("there is no carrrier reference");
+ goto ERROR;
+ }
+
+ /* check version */
+ if (rec->payload_s.buffer[0] != CH_VERSION)
+ {
+ DEBUG_ERR_MSG("connection handover version"
+ " is not matched");
+ goto ERROR;
+ }
+
+ LOGD("[%s] END", __func__);
+
+ return true;
+
+ERROR :
+ LOGD("[%s] END", __func__);
+
+ return false;
+}
+
+static int _net_nfc_server_handover_iterate_carrier_configs_step(
+ net_nfc_server_handover_create_config_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if (context == NULL)
+ {
+ return 0;
+ }
+
+ if (context->cb != NULL)
+ {
+ context->cb(NET_NFC_OK, context->ndef_message,
+ context->user_param);
+ }
+
+ if (context->ndef_message != NULL)
+ {
+ net_nfc_util_free_ndef_message(context->ndef_message);
+ }
+
+ _net_nfc_util_free_mem(context);
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+static int _net_nfc_server_handover_append_wifi_carrier_config(
+ net_nfc_server_handover_create_config_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ switch (context->step)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_MSG("STEP [1]");
+
+ context->step = NET_NFC_LLCP_STEP_02;
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_MSG("STEP [2]");
+
+ context->step = NET_NFC_LLCP_STEP_03;
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_MSG("STEP [3]");
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_MSG("STEP return");
+
+ /* complete and return to upper step */
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_to_next,
+ (gpointer)context);
+ break;
+
+ default :
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+static int _net_nfc_server_handover_iterate_carrier_configs_to_next(
+ net_nfc_server_handover_create_config_context_t *context)
+{
+ if (context->result == NET_NFC_OK || context->result == NET_NFC_BUSY)
+ {
+ if (context->type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
+ if (context->current_type <
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
+ context->current_type++;
+ }
+ }
+ else
+ {
+ context->current_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+ }
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
+ (gpointer)context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("context->result is error [%d]", context->result);
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
+ (gpointer)context);
+ }
+
+ return 0;
+}
+
+static int _net_nfc_server_handover_iterate_create_carrier_configs(
+ net_nfc_server_handover_create_config_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ switch (context->current_type)
+ {
+ case NET_NFC_CONN_HANDOVER_CARRIER_BT :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]");
+ net_nfc_server_handover_bt_get_carrier_record(
+ _net_nfc_server_handover_bt_get_carrier_record_cb,
+ context);
+ break;
+
+// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
+// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
+// g_idle_add(
+// (GSourceFunc)net_nfc_service_llcp_handover_append_wifi_carrier_config,
+// context);
+// break;
+
+// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
+// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
+// g_idle_add(
+// (GSourceFunc)_net_nfc_server_handover_append_wifi_carrier_config,
+// context);
+// break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
+ (gpointer)context);
+ break;
+
+ default :
+ DEBUG_MSG("[unknown : %d]", context->current_type);
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_step,
+ (gpointer)context);
+ break;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return 0;
+}
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_requester_carrier_configs(
+ net_nfc_conn_handover_carrier_type_e type,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_server_handover_create_config_context_t *context = NULL;
+
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->type = type;
+ if (type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
+ context->current_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ }
+ else
+ context->current_type = context->type;
+
+ context->cb = cb;
+ context->user_param = user_param;
+ net_nfc_util_create_handover_request_message(
+ &context->ndef_message);
+
+ /* append carrier record */
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
+ (gpointer)context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return result;
+}
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_selector_carrier_configs(
+ net_nfc_conn_handover_carrier_type_e type,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_server_handover_create_config_context_t *context = NULL;
+
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->type = type;
+ if (type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
+ context->current_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ }
+ else
+ context->current_type = context->type;
+ context->cb = cb;
+ context->user_param = user_param;
+ net_nfc_util_create_handover_select_message(
+ &context->ndef_message);
+
+ /* append carrier record */
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_create_carrier_configs,
+ (gpointer)context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return result;
+}
+
+static net_nfc_error_e
+_net_nfc_server_handover_create_low_power_selector_message(
+ ndef_message_s *request_msg,
+ ndef_message_s *select_msg)
+{
+ net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
+ unsigned int carrier_count = 0;
+
+ LOGD("[%s] START", __func__);
+
+ if (request_msg == NULL || select_msg == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if ((result = net_nfc_util_get_alternative_carrier_record_count(
+ request_msg,
+ &carrier_count)) == NET_NFC_OK)
+ {
+ int idx;
+ ndef_record_s *carrier_record = NULL;
+ net_nfc_conn_handover_carrier_type_e carrier_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ /* check each carrier record and create matched record */
+ for (idx = 0; idx < carrier_count; idx++)
+ {
+ if ((net_nfc_util_get_alternative_carrier_type(
+ request_msg,idx,&carrier_type) != NET_NFC_OK) ||
+ (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN))
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative"
+ "_carrier_type failed or unknown");
+ continue;
+ }
+
+ DEBUG_SERVER_MSG("carrier type = [%d]", carrier_type);
+
+ /* add temporary config record */
+ {
+ net_nfc_carrier_config_s *config = NULL;
+
+ if ((result = net_nfc_util_create_carrier_config(
+ &config,carrier_type)) == NET_NFC_OK)
+ {
+ if ((result =
+ net_nfc_util_create_ndef_record_with_carrier_config(
+ &carrier_record,config)) == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("net_nfc_util_create_ndef_record_"
+ "with_carrier_config success");
+ }
+ else
+ {
+ DEBUG_ERR_MSG("create_ndef_record_with_carrier_config "
+ "failed [%d]", result);
+ net_nfc_util_free_carrier_config(config);
+ continue;
+ }
+
+ net_nfc_util_free_carrier_config(config);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_local_bt_address return NULL");
+ continue;
+ }
+ }
+
+ /* append carrier configure record to selector message */
+ if ((result = net_nfc_util_append_carrier_config_record(
+ select_msg,
+ carrier_record,
+ NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE)) == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("net_nfc_util_append_carrier_config_record success");
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_append_carrier_config_record"
+ " failed [%d]", result);
+
+ net_nfc_util_free_record(carrier_record);
+ }
+ }
+
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed");
+ }
+
+ LOGD("[%s] END", __func__);
+
+ return result;
+}
+
+static net_nfc_error_e _net_nfc_server_handover_process_carrier_record(
+ ndef_record_s *carrier,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_server_handover_process_config_context_t *context = NULL;
+
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ net_nfc_conn_handover_carrier_type_e type;
+
+ net_nfc_util_get_alternative_carrier_type_from_record(
+ carrier,
+ &type);
+
+ context->type = type;
+ context->user_param = user_param;
+ context->cb = cb;
+ context->step = NET_NFC_LLCP_STEP_01;
+
+ /* process carrier record */
+ switch (type)
+ {
+ case NET_NFC_CONN_HANDOVER_CARRIER_BT :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]");
+ net_nfc_server_handover_bt_process_carrier_record(
+ carrier,
+ _net_nfc_server_handover_bt_process_carrier_record_cb,
+ context);
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
+ _net_nfc_util_free_mem(context);
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
+ _net_nfc_util_free_mem(context);
+ break;
+
+ default :
+ DEBUG_MSG("[unknown]");
+ _net_nfc_util_free_mem(context);
+ break;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("alloc failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return result;
+}
+
+#if 0
+static net_nfc_error_e _net_nfc_server_handover_snep_client_cb(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ _net_nfc_server_handover_client_context_t *context =
+ (_net_nfc_server_handover_client_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ switch (type) {
+ case SNEP_RESP_SUCCESS :
+ {
+ ndef_message_s *selector;
+
+ result = _net_nfc_server_handover_create_selector_from_rawdata(
+ &selector,
+ data);
+ if (result == NET_NFC_OK) {
+ if (false /* is low power ??? */) {
+ result =
+ _net_nfc_server_handover_process_selector_msg(
+ selector,
+ user_param);
+ } else {
+ result =
+ _net_nfc_server_handover_process_selector_msg(
+ selector,
+ user_param);
+ }
+
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_process"
+ "_selector_msg failed [%d]",result);
+ if (context->cb != NULL) {
+ context->cb(result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+
+ net_nfc_util_free_ndef_message(selector);
+ } else {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create"
+ "_selector_from_rawdata failed [%d]",result);
+ if (context->cb != NULL) {
+ context->cb(result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+ }
+ break;
+
+ case SNEP_RESP_BAD_REQ :
+ case SNEP_RESP_EXCESS_DATA :
+ case SNEP_RESP_NOT_FOUND :
+ case SNEP_RESP_NOT_IMPLEMENT :
+ case SNEP_RESP_REJECT :
+ case SNEP_RESP_UNSUPPORTED_VER :
+ default :
+ {
+ DEBUG_ERR_MSG("error response [0x%02x]", type);
+ if (context->cb != NULL) {
+ context->cb(result, context->type, NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+ break;
+ }
+
+ return result;
+}
+
+
+static void _net_nfc_server_handover_create_requester_carrier_configs_cb(
+ net_nfc_error_e result,
+ ndef_message_s *msg,
+ void *user_param)
+{
+ _net_nfc_server_handover_client_context_t *context =
+ (_net_nfc_server_handover_client_context_t *)user_param;
+ data_s data;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ if (msg != NULL) {
+ /* convert ndef message */
+ if ((result = _net_nfc_server_handover_convert_ndef_message_to_data(msg,
+ &data)) == NET_NFC_OK) {
+ net_nfc_service_snep_client(context->handle,
+ SNEP_SAN,
+ 0,
+ SNEP_REQ_GET,
+ &data,
+ _net_nfc_server_handover_snep_client_cb,
+ context);
+
+ net_nfc_util_free_data(&data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_convert"
+ "_ndef_message_to_datafailed [%d]",result);
+ if (context->cb != NULL)
+ {
+ context->cb(result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("null param, [%d]", result);
+ if (context->cb != NULL)
+ {
+ context->cb(result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+}
+#endif
+
+
+#if 0
+
+static void _net_nfc_server_handover_server_create_carrier_configs_cb(
+ net_nfc_error_e result,
+ ndef_message_s *selector,
+ void *user_param)
+{
+ _net_nfc_server_handover_create_config_context_t *context =
+ (_net_nfc_server_handover_create_config_context_t *)user_param;
+ data_s data;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ if (result == NET_NFC_OK)
+ {
+ result = _net_nfc_server_handover_convert_ndef_message_to_data(
+ selector,
+ &data);
+
+ if (result == NET_NFC_OK)
+ {
+ /* process message */
+ _net_nfc_server_handover_process_carrier_record(
+ context->record,
+ NULL,
+ NULL);
+
+ result = net_nfc_service_snep_server_send_get_response(
+ context->user_param,
+ &data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_service_snep_server"
+ "_send_get_response failed [%d]",result);
+ }
+ net_nfc_util_free_data(&data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_convert_ndef_message_to_data"
+ "failed [%d]",result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg"
+ "failed [%d]",result);
+ }
+
+ _net_nfc_util_free_mem(context);
+}
+
+static net_nfc_error_e _net_nfc_server_handover_create_selector_msg(
+ net_nfc_snep_handle_h handle,
+ ndef_message_s *request,
+ void *user_param)
+{
+ net_nfc_error_e result;
+ uint32_t count;
+
+ net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
+
+ /* get requester message */
+ if ((result = net_nfc_util_get_alternative_carrier_record_count(
+ request,
+ &count)) == NET_NFC_OK)
+ {
+ if (1/* power state */ || count == 1)
+ {
+ ndef_record_s *record = NULL;
+
+ /* fill alternative carrier information */
+ if ((result =
+ _net_nfc_server_handover_get_carrier_record_by_priority_order(
+ request,
+ &record)) == NET_NFC_OK)
+ {
+ net_nfc_conn_handover_carrier_type_e type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ if ((result = net_nfc_util_get_alternative_carrier_type_from_record(
+ record,
+ &type)) == NET_NFC_OK)
+ {
+ _net_nfc_server_handover_create_config_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ context->user_param = handle;
+
+ net_nfc_util_create_record(record->TNF,
+ &record->type_s, &record->id_s,
+ &record->payload_s,
+ &context->record);
+
+ if ((result = _net_nfc_server_handover_create_selector_carrier_configs(
+ type,
+ _net_nfc_server_handover_server_create_carrier_configs_cb,
+ context)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_create_selector_carrier_configs "
+ "failed [%d]", result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("get_alternative_carrier_type_from_record "
+ "failed [%d]", result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("r_get_carrier_record_by_priority_order"
+ " failed [%d]", result);
+ }
+ }
+ else /* low power && count > 1 */
+ {
+ ndef_message_s selector;
+
+ if ((result = _net_nfc_server_handover_create_low_power_selector_message(
+ request,
+ &selector)) == NET_NFC_OK)
+ {
+ _net_nfc_server_handover_server_create_carrier_configs_cb(
+ NET_NFC_OK,
+ &selector,
+ user_param);
+
+ net_nfc_util_free_ndef_message(&selector);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_create_low_power_selector_message"
+ "failed [%d]", result);
+ }
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count"
+ "failed [%d]", result);
+ }
+
+ return result;
+}
+
+
+static net_nfc_error_e _net_nfc_server_handover_create_server_cb(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("type [0x%02x], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ if (result != NET_NFC_OK || data == NULL || data->buffer == NULL)
+ {
+ /* restart */
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ switch (type)
+ {
+ case SNEP_REQ_GET :
+ {
+ ndef_message_s *request;
+
+ /* TODO : send select response to requester */
+ result =
+ _net_nfc_server_handover_create_requester_from_rawdata(
+ &request,
+ data);
+ if (result == NET_NFC_OK) {
+ if (1/* TODO : check version */)
+ {
+ _net_nfc_server_handover_create_selector_msg(
+ handle,
+ request,
+ user_param);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("not supported version [0x%x]",
+ result);
+
+ result = NET_NFC_NOT_SUPPORTED;
+ }
+
+ net_nfc_util_free_ndef_message(request);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create"
+ "_requester_from_rawdata failed [%d]",result);
+ }
+ }
+ break;
+
+ case SNEP_REQ_PUT :
+ DEBUG_ERR_MSG("PUT request doesn't supported");
+ result = NET_NFC_NOT_SUPPORTED;
+ break;
+
+ default :
+ DEBUG_ERR_MSG("error [%d]", result);
+ break;
+ }
+
+ return result;
+}
+#else
+
+
+
+static net_nfc_error_e _net_nfc_server_handover_select_carrier_record(
+ ndef_message_s *request,
+ net_nfc_conn_handover_carrier_type_e *type,
+ ndef_record_s **record)
+{
+ net_nfc_error_e result;
+ uint32_t count;
+
+ *record = NULL;
+ *type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ /* get requester message */
+ if ((result = net_nfc_util_get_alternative_carrier_record_count(request,
+ &count)) == NET_NFC_OK)
+ {
+ if (1/* power state */ || count == 1)
+ {
+ ndef_record_s *temp;
+
+ /* fill alternative carrier information */
+ if ((result =
+ _net_nfc_server_handover_get_carrier_record_by_priority_order(
+ request,
+ &temp)) == NET_NFC_OK)
+ {
+ if ((result =
+ net_nfc_util_get_alternative_carrier_type_from_record(
+ temp,
+ type)) == NET_NFC_OK)
+ {
+ net_nfc_util_create_record(temp->TNF,
+ &temp->type_s, &temp->id_s,
+ &temp->payload_s,
+ record);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative"
+ "_carrier_type_from_record failed [%d]", result);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_handover_get_carrier_record"
+ "_by_priority_order failed [%d]", result);
+ }
+ }
+ else /* low power && count > 1 */
+ {
+ result = NET_NFC_INVALID_STATE;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count "
+ "failed [%d]", result);
+ }
+
+ return result;
+}
+
+#endif
+
+static void _net_nfc_server_handover_create_carrier_configs_2_cb(
+ net_nfc_error_e result,
+ ndef_message_s *selector,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_create_carrier_config_cb"
+ "result [%d]",result);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->result = result;
+
+ if (result == NET_NFC_OK) {
+ result = _net_nfc_server_handover_convert_ndef_message_to_data(
+ selector,
+ &context->data);
+
+ DEBUG_SERVER_MSG("selector message created, length [%d]",
+ context->data.length);
+
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg failed [%d]",
+ result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_get_response_process(context);
+}
+
+static void _net_nfc_server_handover_process_carrier_record_2_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process_carrier_record_cb"
+ "result [%d]",result);
+
+ context->result = result;
+ if (result == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_04;
+ }
+ else
+ {
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ context->data.length = data->length;
+ _net_nfc_util_alloc_mem(context->data.buffer, context->data.length);
+ memcpy(context->data.buffer, data->buffer, context->data.length);
+
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_get_response_process(
+ net_nfc_handover_context_t *context)
+{
+ net_nfc_error_e result;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ result = _net_nfc_server_handover_create_selector_carrier_configs(
+ context->type,
+ _net_nfc_server_handover_create_carrier_configs_2_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_"
+ "selector_carrier_config failed [%d]",result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
+
+ result = _net_nfc_server_handover_process_carrier_record(
+ context->record,
+ _net_nfc_server_handover_process_carrier_record_2_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_record"
+ "failed [%d]",result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ /* response select message */
+ result = net_nfc_server_snep_server_send_get_response(
+ (net_nfc_snep_handle_h)context->handle,
+ &context->data);
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
+ break;
+
+ default :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
+ /* TODO */
+ break;
+ }
+}
+
+static bool _net_nfc_server_handover_get_response_cb(
+ net_nfc_snep_handle_h handle,
+ uint32_t type,
+ uint32_t max_len,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_error_e result;
+ ndef_message_s *request;
+
+ DEBUG_SERVER_MSG("type [%d], data [%p], user_param [%p]",
+ type, data, user_param);
+
+ if (data == NULL || data->buffer == NULL)
+ {
+ /* restart */
+ return false;
+ }
+
+ /* TODO : send select response to requester */
+ result = _net_nfc_server_handover_create_requester_from_rawdata(
+ &request,
+ data);
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_conn_handover_carrier_type_e type;
+ ndef_record_s *record;
+
+ if (_net_nfc_server_handover_select_carrier_record(
+ request,
+ &type,
+ &record) == NET_NFC_OK)
+ {
+ net_nfc_handover_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ if (context != NULL)
+ {
+ context->handle = (void *)handle;
+ context->type = type;
+ context->user_param = user_param;
+ context->state = NET_NFC_LLCP_STEP_02;
+
+ net_nfc_util_create_record(record->TNF,
+ &record->type_s,
+ &record->id_s,
+ &record->payload_s,
+ &context->record);
+
+ _net_nfc_server_handover_get_response_process(context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ /* low power */
+ }
+
+ net_nfc_util_free_ndef_message(request);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("it is not handover requester message, [%d]",
+ result);
+ }
+
+ return (result == NET_NFC_OK);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+static void _net_nfc_server_handover_server_process_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process"
+ "_carrier_record_cb result [%d]",result);
+
+ context->result = result;
+ if (result == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_04;
+ }
+ else
+ {
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_server_create_carrier_config_cb(
+ net_nfc_error_e result,
+ ndef_message_s *selector,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_create"
+ "_carrier_config_cb,result [%d]",result);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ result = _net_nfc_server_handover_convert_ndef_message_to_data(
+ selector,
+ &context->data);
+ DEBUG_SERVER_MSG("selector message created, length [%d]",
+ context->data.length);
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg"
+ " failed [%d]", result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_server_recv_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+ ndef_message_s *request;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_recv_cb,"
+ " socket [%x], result [%d]", socket, result);
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ result = _net_nfc_server_handover_create_requester_from_rawdata(
+ &request,
+ data);
+
+ if (result == NET_NFC_OK)
+ {
+ ndef_record_s *record;
+
+ if (_net_nfc_server_handover_select_carrier_record(
+ request,
+ &context->type,
+ &record) == NET_NFC_OK)
+ {
+ net_nfc_util_create_record(record->TNF,
+ &record->type_s, &record->id_s,
+ &record->payload_s,
+ &context->record);
+
+ context->state = NET_NFC_LLCP_STEP_02;
+ }
+ else
+ {
+ /* low power */
+ context->state = NET_NFC_LLCP_STEP_06;
+ }
+
+ net_nfc_util_free_ndef_message(request);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create"
+ "_requester_from_rawdata failed [%d]",result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_receive failed [%d]",
+ result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_server_send_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_send_cb"
+ " socket [%x], result [%d]", socket, result);
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_01;
+ net_nfc_util_free_data(&context->data);
+ net_nfc_util_free_record(context->record);
+ context->record = NULL;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_send failed [%d]",
+ result);
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(context);
+}
+
+static void _net_nfc_server_handover_server_process(
+ net_nfc_handover_context_t *context)
+{
+ if (context == NULL)
+ {
+ return;
+ }
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
+
+ /* receive request message */
+ net_nfc_server_llcp_simple_receive(context->handle,
+ context->socket,
+ _net_nfc_server_handover_server_recv_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ context->result = _net_nfc_server_handover_create_selector_carrier_configs(
+ context->type,
+ _net_nfc_server_handover_server_create_carrier_config_cb,
+ context);
+
+ if (context->result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector"
+ "_carrier_configs failed [%d]", context->result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
+
+ context->result = _net_nfc_server_handover_process_carrier_record(
+ context->record,
+ _net_nfc_server_handover_server_process_carrier_record_cb,
+ context);
+ if (context->result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_"
+ "record failed [%d]",context->result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ /* send select message */
+ net_nfc_server_llcp_simple_send(
+ context->handle,
+ context->socket,
+ &context->data,
+ _net_nfc_server_handover_server_send_cb,
+ context);
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("handover_server failed, [%d]",
+ context->result);
+
+ /* restart?? */
+ break;
+
+ default :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
+ /* TODO */
+ break;
+ }
+}
+
+static void _net_nfc_server_handover_server_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_ERR_MSG("result [%d], socket [%x], user_param [%p]",
+ result, socket, user_param);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ net_nfc_util_free_record(context->record);
+ net_nfc_util_free_data(&context->data);
+ _net_nfc_util_free_mem(user_param);
+}
+
+static void _net_nfc_server_handover_server_incomming_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("result [%d], socket [%x], user_param [%p]",
+ result, socket, user_param);
+
+ net_nfc_handover_context_t *accept_context = NULL;
+
+ _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context));
+ if (accept_context == NULL)
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+
+ result = NET_NFC_ALLOC_FAIL;
+ goto ERROR;
+ }
+
+ accept_context->handle = handle;
+ accept_context->socket = socket;
+ accept_context->state = NET_NFC_LLCP_STEP_01;
+
+ result = net_nfc_server_llcp_simple_accept(
+ handle,
+ socket,
+ _net_nfc_server_handover_server_error_cb,
+ accept_context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_accept failed, [%d]",
+ result);
+
+ goto ERROR;
+ }
+
+ _net_nfc_server_handover_server_process(accept_context);
+
+ return;
+
+ERROR :
+ if (accept_context != NULL)
+ {
+ _net_nfc_util_free_mem(accept_context);
+ }
+
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ /* TODO : restart ?? */
+}
+
+net_nfc_error_e net_nfc_server_handover_default_server_start(
+ net_nfc_target_handle_s *handle)
+{
+ net_nfc_error_e result;
+
+ /* start default handover server using snep */
+ result =
+ net_nfc_server_snep_default_server_register_get_response_cb(
+ _net_nfc_server_handover_get_response_cb,
+ NULL);
+
+ /* start default handover server */
+ result = net_nfc_server_llcp_simple_server(
+ handle,
+ CH_SAN,
+ CH_SAP,
+ _net_nfc_server_handover_server_incomming_cb,
+ _net_nfc_server_handover_server_error_cb,
+ NULL);
+
+ if (result == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("start handover server, san [%s], sap [%d]",
+ CH_SAN,CH_SAP);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_server failed, [%d]",
+ result);
+ }
+
+ return result;
+}
+
+static void _handover_default_activate_cb(int event,
+ net_nfc_target_handle_s *handle,
+ uint32_t sap, const char *san, void *user_param)
+{
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
+ event, handle, sap, san);
+
+ if (event == NET_NFC_LLCP_START) {
+ /* start default handover server using snep */
+ result = net_nfc_server_snep_default_server_register_get_response_cb(
+ _net_nfc_server_handover_get_response_cb, NULL);
+
+ /* start default handover server */
+ result = net_nfc_server_llcp_simple_server(handle,
+ CH_SAN, CH_SAP,
+ _net_nfc_server_handover_server_incomming_cb,
+ _net_nfc_server_handover_server_error_cb, NULL);
+
+ if (result == NET_NFC_OK) {
+ DEBUG_SERVER_MSG("start handover server, san [%s], sap [%d]",
+ CH_SAN, CH_SAP);
+ } else {
+ DEBUG_ERR_MSG("net_nfc_service_llcp_server failed, [%d]",
+ result);
+ }
+ } else if (event == NET_NFC_LLCP_UNREGISTERED) {
+ /* unregister server, do nothing */
+ }
+}
+
+net_nfc_error_e net_nfc_server_handover_default_server_register()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default snep server */
+ return net_nfc_server_llcp_register_service(id,
+ CH_SAP,
+ CH_SAN,
+ _handover_default_activate_cb,
+ NULL);
+}
+
+net_nfc_error_e net_nfc_server_handover_default_server_unregister()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default snep server */
+ return net_nfc_server_llcp_unregister_service(id,
+ CH_SAP,
+ CH_SAN);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+static void _net_nfc_server_handover_client_post_process_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+static void _net_nfc_server_handover_client_process_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_handover_server_process"
+ "_carrier_record_cb,result [%d]",result);
+
+ context->result = result;
+
+ net_nfc_util_free_data(&context->data);
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_util_alloc_data(&context->data, data->length);
+ memcpy(context->data.buffer, data->buffer, data->length);
+
+ context->state = NET_NFC_LLCP_STEP_05;
+ }
+ else
+ {
+ context->state = NET_NFC_MESSAGE_LLCP_ERROR;
+ }
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+static void _net_nfc_server_handover_client_recv_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ ndef_message_s *selector;
+ ndef_record_s *record;
+
+ result = _net_nfc_server_handover_create_selector_from_rawdata(
+ &selector,
+ data);
+
+ if (result == NET_NFC_OK)
+ {
+ result =
+ _net_nfc_server_handover_get_carrier_record_by_priority_order(
+ selector,
+ &record);
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_util_create_record(
+ record->TNF,
+ &record->type_s, &record->id_s,
+ &record->payload_s,
+ &context->record);
+
+ context->state = NET_NFC_LLCP_STEP_04;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_get_carrier_record_by_priority_order"
+ " failed, [%d]",result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create"
+ "_selector_from_rawdata failed, [%d]",result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_receive failed, [%d]",
+ result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+static void _net_nfc_server_handover_client_send_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->result = result;
+
+ net_nfc_util_free_data(&context->data);
+
+ if (result == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client failed, [%d]",
+ result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+static void _net_nfc_server_handover_client_create_carrier_configs_cb(
+ net_nfc_error_e result,
+ ndef_message_s *msg,
+ void *user_param)
+{
+ net_nfc_handover_context_t *context =
+ (net_nfc_handover_context_t *)user_param;
+
+ if (context == NULL) {
+ return;
+ }
+
+ context->result = result;
+
+ if (msg != NULL)
+ {
+ if ((result =
+ _net_nfc_server_handover_convert_ndef_message_to_data(
+ msg,
+ &context->data)) == NET_NFC_OK)
+ {
+ context->state = NET_NFC_LLCP_STEP_02;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_convert_ndef_"
+ "message_to_data failed [%d]",result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("null param, [%d]", result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ }
+
+ _net_nfc_server_handover_client_process(context);
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+static void _net_nfc_server_handover_client_process(
+ net_nfc_handover_context_t *context)
+{
+ net_nfc_error_e result;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
+
+ if ((result = _net_nfc_server_handover_create_requester_carrier_configs(
+ context->type,
+ _net_nfc_server_handover_client_create_carrier_configs_cb,
+ context)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_create_requester"
+ "_carrier_configs failed [%d]",result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ /* send request */
+ net_nfc_server_llcp_simple_send(
+ context->handle,
+ context->socket,
+ &context->data,
+ _net_nfc_server_handover_client_send_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
+
+ /* receive response */
+ net_nfc_server_llcp_simple_receive(context->handle,
+ context->socket,
+ _net_nfc_server_handover_client_recv_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ result = _net_nfc_server_handover_process_carrier_record(
+ context->record,
+ _net_nfc_server_handover_client_process_carrier_record_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_server_handover_process_carrier_record"
+ "failed [%d]",result);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_05 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_05");
+
+ /* start post process */
+ if (context->type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
+ {
+ net_nfc_server_handover_bt_post_process(
+ &context->data,
+ _net_nfc_server_handover_client_post_process_cb,
+ context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("not supported...");
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
+
+ /* complete and invoke callback */
+ _net_nfc_server_handover_send_response(
+ context->user_param,
+ &context->data,
+ context->result);
+
+ net_nfc_util_free_data(&context->data);
+ net_nfc_util_free_record(context->record);
+ _net_nfc_util_free_mem(context);
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ default :
+ DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
+
+ _net_nfc_server_handover_send_response(
+ context->user_param,
+ NULL,
+ context->result);
+ break;
+ }
+}
+
+
+
+static void _net_nfc_server_handover_client_connected_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("result [%d], socket [%x], user_param [%p]",
+ result, socket, user_param);
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_handover_context_t *context = NULL;
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ if (context != NULL)
+ {
+ context->handle = handle;
+ context->socket = socket;
+ context->state = NET_NFC_LLCP_STEP_01;
+ context->user_param = user_param;
+ _net_nfc_server_handover_client_process(context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client"
+ " failed, [%d]", result);
+ }
+}
+
+static void _net_nfc_server_handover_client_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+
+ DEBUG_ERR_MSG("result [%d], socket [%x], user_param [%p]",
+ result, socket, user_param);
+
+ if (false)
+ {
+ _net_nfc_server_handover_send_response(user_param, NULL, result);
+ }
+
+ net_nfc_controller_llcp_socket_close(socket, &result);
+}
+
+
+net_nfc_error_e net_nfc_server_handover_default_client_start(
+ net_nfc_target_handle_s *handle,
+ void *user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_server_llcp_simple_client(
+ handle,
+ CH_SAN,
+ CH_SAP,
+ _net_nfc_server_handover_client_connected_cb,
+ _net_nfc_server_handover_client_error_cb,
+ user_data);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client"
+ " failed, [%d]",result);
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <arpa/inet.h>
+
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_llcp.h"
+
+#include "net_nfc_server_process_npp.h"
+
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_app_util_internal.h"
+#include "net_nfc_debug_internal.h"
+
+typedef struct _net_nfc_npp_entity_t
+{
+ uint8_t op;
+ uint32_t length;
+ uint8_t data[0];
+}
+__attribute__ ((packed)) net_nfc_npp_entity_t;
+
+typedef struct _net_nfc_npp_msg_t
+{
+ uint8_t version;
+ uint32_t entity_count;
+ net_nfc_npp_entity_t entity[0];
+}
+__attribute__ ((packed)) net_nfc_npp_msg_t;
+
+typedef struct _NppData NppData;
+
+struct _NppData
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_llcp_socket_t socket;
+ uint32_t type;
+ data_s data;
+ net_nfc_server_npp_callback callback;
+ gpointer user_data;
+};
+
+typedef struct _NppClientStartData NppClientStartData;
+
+struct _NppClientStartData
+{
+ net_nfc_target_handle_s *handle;
+ int client;
+ gpointer user_data;
+};
+
+#define NPP_SAN "com.android.npp"
+#define NPP_SAP 0x10
+
+#define NPP_HEADER_LEN (sizeof(net_nfc_npp_msg_t))
+#define NPP_ENTITY_HEADER_LEN (sizeof(net_nfc_npp_entity_t))
+
+#define NPP_MAJOR_VER 0
+#define NPP_MINOR_VER 1
+#define NPP_VERSION ((NPP_MAJOR_VER << 4) | NPP_MINOR_VER)
+
+#define NPP_NDEF_ENTRY 0x00000001
+#define NPP_ACTION_CODE 0x01
+
+static net_nfc_error_e npp_create_message(data_s *data,
+ data_s *message);
+
+/* server */
+static void npp_server_receive_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_server_process(NppData *npp_data);
+
+static void npp_listen_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+/* client */
+static void npp_client_disconnected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
+static void npp_client_send_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_client_process(NppData *npp_data);
+
+static void npp_connected_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_socket_error_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_default_server_cb(net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data);
+
+static void npp_default_client_cb(net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data);
+
+static net_nfc_error_e npp_create_message(data_s *data,
+ data_s *message)
+{
+ uint32_t length = NPP_HEADER_LEN;
+ net_nfc_npp_msg_t *msg;
+
+ if (data != NULL)
+ length += NPP_ENTITY_HEADER_LEN + data->length;
+
+ message->buffer = g_new0(uint8_t, length);
+ message->length = length;
+
+ msg = (net_nfc_npp_msg_t *)message->buffer;
+ msg->version = NPP_VERSION;
+
+ if (data != NULL)
+ {
+ net_nfc_npp_entity_t *entity;
+
+ DEBUG_SERVER_MSG("data->length [%d]", data->length);
+
+ msg->entity_count = htonl(1);
+
+ entity = msg->entity;
+
+ entity->op = NPP_ACTION_CODE;
+ entity->length = htonl(data->length);
+ /* copy ndef information to response msg */
+ memcpy(entity->data, data->buffer, data->length);
+ }
+ else
+ {
+ msg->entity_count = 0;
+ }
+
+ return NET_NFC_OK;
+}
+
+static void npp_server_receive_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+
+ net_nfc_npp_msg_t *message;
+ net_nfc_npp_entity_t *entity;
+
+ data_s ndef_msg = { NULL, 0 };
+
+ uint32_t length;
+ uint32_t entity_count;
+ uint32_t i;
+
+ npp_data = (NppData *)user_data;
+
+ if (npp_data == NULL)
+ return;
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("error [%d]", result);
+
+ if(npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+ return;
+ }
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is NULL");
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ if (data->buffer == NULL || data->length == 0)
+ {
+ DEBUG_ERR_MSG("Wrong data");
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ message = (net_nfc_npp_msg_t *)data->buffer;
+
+ if (data->length < NPP_HEADER_LEN)
+ {
+ DEBUG_ERR_MSG("too short data, length [%d]",
+ data->length);
+ /* FIXME!!! what should I do. */
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ if (GET_MAJOR_VER(message->version) > NPP_MAJOR_VER ||
+ GET_MINOR_VER(message->version > NPP_MINOR_VER))
+ {
+ DEBUG_ERR_MSG("not supported version, version [0x%02x]",
+ message->version);
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_NOT_SUPPORTED,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ entity_count = htonl(message->entity_count);
+
+ if (entity_count > NPP_NDEF_ENTRY)
+ {
+ DEBUG_ERR_MSG("too many entities, [%d]",
+ message->entity_count);
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ for (i = 0; i < entity_count; i++)
+ {
+ entity = (message->entity + i);
+
+ if (entity->op != NPP_ACTION_CODE) {
+ DEBUG_ERR_MSG("not supported action code, [0x%02x]",
+ entity->op);
+
+ if(npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_INVALID_PARAM,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data);
+ return;
+ }
+
+ length = htonl(entity->length);
+
+ DEBUG_SERVER_MSG("action code [0x%02x], length [%d]",
+ entity->op, length);
+
+ if (length > 0)
+ {
+ /* buffer create */
+ ndef_msg.buffer = g_new0(uint8_t, length);
+ ndef_msg.length = length;
+
+ memcpy(ndef_msg.buffer, entity->data, length);
+ }
+ }
+
+ if (npp_data->callback)
+ npp_data->callback(result, &ndef_msg, npp_data->user_data);
+
+ g_free(ndef_msg.buffer);
+ g_free(npp_data);
+}
+
+
+static void npp_server_process(NppData *npp_data)
+{
+ net_nfc_error_e result;
+ if (npp_data == NULL)
+ return;
+
+ /* receive request */
+ result = net_nfc_server_llcp_simple_receive(npp_data->handle,
+ npp_data->socket,
+ npp_server_receive_cb,
+ npp_data);
+ if (result != NET_NFC_OK)
+ {
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+ }
+}
+
+static void npp_listen_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+ NppData *accept_data;
+
+ npp_data = (NppData *)user_data;
+ if (npp_data == NULL)
+ return;
+
+ DEBUG_SERVER_MSG("npp_listen_cb, incoming socket [%#x], result [%d]",
+ socket, result);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("listen failed [%d]", result);
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+ return;
+ }
+
+ /* start npp server */
+ accept_data = g_new0(NppData, 1);
+
+ accept_data->handle = npp_data->handle;
+ accept_data->socket = socket;
+ accept_data->callback = npp_data->callback;
+ accept_data->user_data = npp_data->user_data;
+
+ result = net_nfc_server_llcp_simple_accept(handle,
+ socket,
+ npp_socket_error_cb,
+ accept_data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed",
+ "net_nfc_server_llcp_simple_accept");
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+ g_free(accept_data);
+
+ return;
+ }
+
+ DEBUG_SERVER_MSG("socket [%x] accepted.. waiting for request message",
+ socket);
+
+ npp_server_process(accept_data);
+ g_free(npp_data);
+}
+
+/* client */
+static void npp_client_disconnected_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("disconnected! [%d]", result);
+}
+
+static void npp_client_send_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+
+ npp_data = (NppData *)user_data;
+ if (npp_data == NULL)
+ return;
+
+ DEBUG_SERVER_MSG("send complete... [%d]", result);
+
+ if (npp_data->callback)
+ {
+ npp_data->callback(result, NULL, npp_data->user_data);
+ }
+
+ net_nfc_controller_llcp_disconnect(npp_data->handle,
+ npp_data->socket,
+ &result,
+ npp_client_disconnected_cb,
+ NULL);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+}
+
+static void npp_client_process(NppData *npp_data)
+{
+ net_nfc_error_e result;
+ data_s data;
+
+ if (npp_data == NULL)
+ return;
+
+ result = npp_create_message(&npp_data->data, &data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]", "npp_create_message", result);
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+ return;
+ }
+
+ /* send request */
+ result = net_nfc_server_llcp_simple_send(npp_data->handle,
+ npp_data->socket,
+ &data,
+ npp_client_send_cb,
+ npp_data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_server_llcp_simple_send",
+ result);
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+ }
+
+ g_free(data.buffer);
+}
+
+static void npp_connected_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+
+ npp_data = (NppData *)user_data;
+ if (npp_data == NULL)
+ return;
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("connect socket failed, [%d]", result);
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+ return;
+ }
+
+ /*start npp client */
+ DEBUG_SERVER_MSG("socket [%x] connected, send request message.",
+ socket);
+ npp_data->socket = socket;
+
+ npp_client_process(npp_data);
+ return;
+}
+
+static void npp_socket_error_cb(net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ gpointer user_data)
+{
+ NppData *npp_data;
+
+ DEBUG_SERVER_MSG("socket [%x], result [%d]", socket, result);
+
+ npp_data = (NppData *)user_data;
+ if (npp_data == NULL)
+ return;
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+}
+
+static void npp_default_server_cb(net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data)
+{
+ DEBUG_SERVER_MSG("result [%d], data [%p], user_data [%p]",
+ result, data, user_data);
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("npp server receive failed, [%d]", result);
+ return;
+ }
+
+ if (data->buffer == NULL)
+ {
+ DEBUG_ERR_MSG("npp server receive failed, [%d]", result);
+ return;
+ }
+
+ net_nfc_server_p2p_received(data);
+ net_nfc_app_util_process_ndef(data);
+}
+
+static void npp_default_client_cb(net_nfc_error_e result,
+ data_s *data,
+ gpointer user_data)
+{
+ NppClientStartData *npp_client_data;
+
+ DEBUG_SERVER_MSG("result [%d], data [%p], user_data [%p]",
+ result, data, user_data);
+
+ if (user_data == NULL)
+ return;
+
+ npp_client_data = (NppClientStartData *)user_data;
+
+ net_nfc_server_p2p_data_sent(result, npp_client_data->user_data);
+
+ g_free(npp_client_data);
+}
+
+/* public apis */
+net_nfc_error_e net_nfc_server_npp_server(net_nfc_target_handle_s *handle,
+ char *san,
+ sap_t sap,
+ net_nfc_server_npp_callback callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ NppData *npp_data = NULL;
+
+ if (handle == NULL)
+ {
+ DEBUG_ERR_MSG("handle is NULL");
+ return FALSE;
+ }
+
+ if (san == NULL)
+ {
+ DEBUG_ERR_MSG("san is NULL");
+ return FALSE;
+ }
+
+ npp_data = g_new0(NppData, 1);
+
+ npp_data->handle = handle;
+ npp_data->callback = callback;
+ npp_data->user_data = user_data;
+
+ result = net_nfc_server_llcp_simple_server(handle,
+ san,
+ sap,
+ npp_listen_cb,
+ npp_socket_error_cb,
+ npp_data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed",
+ "net_nfc_server_llcp_simple_server");
+
+ if (npp_data->callback)
+ npp_data->callback(result, NULL, npp_data->user_data);
+
+ g_free(npp_data);
+
+ return FALSE;
+ }
+
+ DEBUG_SERVER_MSG("start npp server, san [%s], sap [%d]", san, sap);
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_npp_client(net_nfc_target_handle_s *handle,
+ char *san,
+ sap_t sap,
+ data_s *data,
+ net_nfc_server_npp_callback callback,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;;
+ net_nfc_llcp_config_info_s config;
+
+ NppData *npp_data;
+
+ if (handle == NULL)
+ {
+ DEBUG_ERR_MSG("handle is NULL");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if(net_nfc_controller_llcp_get_remote_config(handle,
+ &config,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed [%d]",
+ "net_nfc_controller_llcp_get_remote_config",
+ result);
+
+ return result;
+ }
+
+ if (config.miu <
+ data->length + NPP_HEADER_LEN + NPP_ENTITY_HEADER_LEN)
+ {
+ DEBUG_ERR_MSG("too large message, max [%d], request [%d]",
+ config.miu - (NPP_HEADER_LEN + NPP_ENTITY_HEADER_LEN),
+ data->length);
+
+ return NET_NFC_INSUFFICIENT_STORAGE;
+ }
+
+ npp_data = g_new0(NppData, 1);
+
+ npp_data->handle = handle;
+ npp_data->callback = callback;
+ npp_data->user_data = user_data;
+
+ npp_data->data.buffer = g_new0(uint8_t, data->length);
+ npp_data->data.length = data->length;
+
+ result = net_nfc_server_llcp_simple_client(handle,
+ san,
+ sap,
+ npp_connected_cb,
+ npp_socket_error_cb,
+ npp_data);
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("%s failed",
+ "net_nfc_server_llcp_simple_client");
+
+ if (npp_data->callback)
+ {
+ npp_data->callback(NET_NFC_UNKNOWN_ERROR,
+ NULL,
+ npp_data->user_data);
+ }
+
+ g_free(npp_data->data.buffer);
+ g_free(npp_data);
+
+ return result;
+ }
+
+ if (san != NULL)
+ {
+ DEBUG_SERVER_MSG("start npp client, san [%s], result [%d]",
+ san, result);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("start npp client, sap [%d], result [%d]",
+ sap, result);
+ }
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_npp_default_server_start(
+ net_nfc_target_handle_s *handle)
+{
+ /* start default npp server */
+ return net_nfc_server_npp_server(handle,
+ NPP_SAN,
+ NPP_SAP,
+ npp_default_server_cb,
+ (gpointer)1234);
+}
+
+static void _npp_default_activate_cb(int event,
+ net_nfc_target_handle_s *handle,
+ uint32_t sap, const char *san, void *user_param)
+{
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
+ event, handle, sap, san);
+
+ if (event == NET_NFC_LLCP_START) {
+ /* start default npp server */
+ result = net_nfc_server_npp_server(handle, (char *)san, sap,
+ npp_default_server_cb, user_param);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_server_npp_server failed, [%d]",
+ result);
+ }
+ } else if (event == NET_NFC_LLCP_UNREGISTERED) {
+ /* unregister server, do nothing */
+ }
+}
+
+net_nfc_error_e net_nfc_server_npp_default_server_register()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default npp server */
+ return net_nfc_server_llcp_register_service(id,
+ NPP_SAP,
+ NPP_SAN,
+ _npp_default_activate_cb,
+ NULL);
+}
+
+net_nfc_error_e net_nfc_server_npp_default_server_unregister()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default npp server */
+ return net_nfc_server_llcp_unregister_service(id,
+ NPP_SAP,
+ NPP_SAN);
+}
+
+net_nfc_error_e net_nfc_server_npp_default_client_start(
+ net_nfc_target_handle_s *handle,
+ data_s *data,
+ int client,
+ gpointer user_data)
+{
+ NppClientStartData *npp_client_data;
+
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (handle == NULL)
+ {
+ DEBUG_ERR_MSG("handle is NULL");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("data is NULL");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (data->buffer == NULL)
+ {
+ DEBUG_ERR_MSG("data->buffer is NULL");
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ npp_client_data = g_new0(NppClientStartData, 1);
+
+ npp_client_data->handle = handle;
+ npp_client_data->client = client;
+ npp_client_data->user_data = user_data;
+
+ result = net_nfc_server_npp_client(handle,
+ NPP_SAN,
+ NPP_SAP,
+ data,
+ npp_default_client_cb,
+ npp_client_data);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_client failed");
+ g_free(npp_client_data);
+ }
+
+ return result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include "net_nfc_server_p2p.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_server_snep.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_app_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+
+
+typedef struct _net_nfc_server_snep_msg_t
+{
+ uint8_t version;
+ uint8_t op;
+ uint32_t length;
+ uint8_t data[0];
+}
+__attribute__ ((packed)) net_nfc_server_snep_msg_t;
+
+typedef struct _net_nfc_server_snep_get_msg_t
+{
+ uint32_t length;
+ uint8_t data[0];
+}
+__attribute__ ((packed)) net_nfc_server_snep_get_msg_t;
+
+typedef struct _net_nfc_server_cb_data_t
+{
+ net_nfc_server_snep_listen_cb cb;
+ void *user_param;
+}
+net_nfc_server_cb_data_t;
+
+typedef struct _net_nfc_server_snep_context_t
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t socket;
+ uint32_t state;
+ uint32_t type;
+ data_s data;
+ net_nfc_server_snep_cb cb;
+ void *user_param;
+ GQueue queue;
+}
+net_nfc_server_snep_context_t;
+
+typedef struct _net_nfc_server_snep_job_t
+{
+ net_nfc_server_snep_context_t *context;
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t socket;
+ uint32_t state;
+ uint32_t type;
+ data_s data;
+ net_nfc_server_snep_cb cb;
+ void *user_param;
+}
+net_nfc_server_snep_job_t;
+
+
+typedef struct __net_nfc_server_snep_server_context_t
+{
+ net_nfc_target_handle_s *handle;
+ int client;
+ void *user_param;
+}
+_net_nfc_server_snep_server_context_t;
+
+typedef struct __net_nfc_server_snep_service_context_t
+{
+ net_nfc_target_handle_s *handle;
+ int client;
+ uint32_t type;
+ data_s data;
+ void *user_param;
+}
+_net_nfc_server_snep_service_context_t;
+
+typedef void (*_net_nfc_server_snep_operation_cb)(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param);
+
+typedef struct _net_nfc_server_snep_op_context_t
+{
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result;
+ int socket;
+ uint32_t state;
+ uint32_t type;
+ uint32_t current;
+ uint16_t miu;
+ data_s data;
+ uint32_t offset;
+ _net_nfc_server_snep_operation_cb cb;
+ void *user_param;
+}
+
+net_nfc_server_snep_op_context_t;
+
+#define SNEP_MAJOR_VER 1
+#define SNEP_MINOR_VER 0
+#define SNEP_VERSION ((SNEP_MAJOR_VER << 4) | SNEP_MINOR_VER)
+
+#define SNEP_HEADER_LEN (sizeof(net_nfc_server_snep_msg_t))
+#define SNEP_MAX_LEN (SNEP_HEADER_LEN + 1024 * 10)
+
+#define SNEP_REQUEST (0)
+#define SNEP_RESPONSE (0x80)
+
+#define SNEP_PAIR_OP(__x) ((__x) ^ SNEP_RESPONSE)
+#define SNEP_MAKE_PAIR_OP(__x, __y) ((SNEP_PAIR_OP(__x) & SNEP_RESPONSE) | (__y))
+
+#define IS_SNEP_REQ(__x) (((__x) & SNEP_RESPONSE) == SNEP_REQUEST)
+#define IS_SNEP_RES(__x) (((__x) & SNEP_RESPONSE) == SNEP_RESPONSE)
+
+static GList *list_listen_cb = NULL;
+
+static void _net_nfc_server_snep_recv(
+ net_nfc_server_snep_op_context_t *context);
+
+static void _net_nfc_server_snep_send(
+ net_nfc_server_snep_op_context_t *context);
+
+static net_nfc_error_e net_nfc_server_snep_recv(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ _net_nfc_server_snep_operation_cb cb,
+ void *user_param);
+
+static net_nfc_error_e net_nfc_server_snep_send(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ uint32_t type,
+ data_s *data,
+ _net_nfc_server_snep_operation_cb cb,
+ void *user_param);
+
+
+static void _net_nfc_server_snep_client_process(
+ net_nfc_server_snep_job_t *job);
+
+static void _net_nfc_server_snep_server_process(
+ net_nfc_server_snep_context_t *context);
+
+/**********************************************************************/
+static bool _net_nfc_server_snep_add_get_response_cb(
+ net_nfc_server_snep_listen_cb cb,
+ void *user_param)
+{
+ net_nfc_server_cb_data_t *data = NULL;
+ bool result = false;
+
+ _net_nfc_util_alloc_mem(data, sizeof(*data));
+ if (data != NULL)
+ {
+ data->cb = cb;
+ data->user_param = user_param;
+
+ list_listen_cb = g_list_append(list_listen_cb, data);
+ if (list_listen_cb != NULL)
+ {
+ result = true;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_list_append failed");
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ }
+
+ return result;
+}
+
+static gint _net_nfc_server_snep_compare_func_cb(
+ gconstpointer a,
+ gconstpointer b)
+{
+ net_nfc_server_cb_data_t *data = (net_nfc_server_cb_data_t *)a;
+
+ if (data->cb == (void *)b)
+ return 0;
+ else
+ return 1;
+}
+
+static void _net_nfc_server_snep_del_get_response_cb(
+ net_nfc_server_snep_listen_cb cb)
+{
+ GList *list;
+
+ list = g_list_find_custom(list_listen_cb,
+ cb,
+ _net_nfc_server_snep_compare_func_cb);
+
+ if (list != NULL)
+ list_listen_cb = g_list_delete_link(list_listen_cb, list);
+}
+
+static bool _net_nfc_server_snep_process_get_response_cb(
+ net_nfc_target_handle_s *handle,
+ data_s *data,
+ uint32_t max_len)
+{
+ GList *list = list_listen_cb;
+
+ while (list != NULL && list->data != NULL)
+ {
+ net_nfc_server_cb_data_t *cb_data =
+ (net_nfc_server_cb_data_t *)list->data;
+
+ if (cb_data->cb != NULL)
+ {
+ DEBUG_SERVER_MSG("invoke callback [%p]", cb_data->cb);
+ if (cb_data->cb(handle,
+ SNEP_REQ_GET,
+ max_len,
+ data,
+ cb_data->user_param) == true)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static net_nfc_server_snep_op_context_t *
+_net_nfc_server_snep_create_send_context(uint32_t type,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context = NULL;
+ uint32_t data_len = 0;
+ net_nfc_server_snep_msg_t *msg;
+ net_nfc_llcp_config_info_s config;
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_llcp_get_remote_config(handle,
+ &config, &result) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_get_remote_config failed, [%d]",
+ result);
+
+ return NULL;
+ }
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context == NULL)
+ {
+ return NULL;
+ }
+
+ if (type == SNEP_REQ_GET)
+ {
+ data_len = sizeof(net_nfc_server_snep_msg_t);
+ }
+
+ if (data != NULL)
+ {
+ data_len += data->length;
+ }
+
+ net_nfc_util_alloc_data(&context->data, SNEP_HEADER_LEN + data_len);
+ if (context->data.buffer == NULL)
+ {
+ _net_nfc_util_free_mem(context);
+ return NULL;
+ }
+
+ msg = (net_nfc_server_snep_msg_t *)context->data.buffer;
+
+ msg->version = SNEP_VERSION;
+ msg->op = type;
+
+ if (data_len > 0)
+ {
+ uint8_t *buffer;
+
+ msg->length = htonl(data_len);
+
+ if (type == SNEP_REQ_GET)
+ {
+ net_nfc_server_snep_msg_t *get_msg =
+ (net_nfc_server_snep_msg_t *)msg->data;
+
+ get_msg->length = htonl(SNEP_MAX_LEN);
+ buffer = get_msg->data;
+ }
+ else
+ {
+ buffer = msg->data;
+ }
+
+ if (data != NULL && data->buffer != NULL)
+ {
+ DEBUG_SERVER_MSG("data->length [%d]", data->length);
+
+ /* copy ndef information to response msg */
+ memcpy(buffer, data->buffer, data->length);
+ }
+ }
+
+ context->handle = handle;
+ context->type = type;
+ context->state = NET_NFC_LLCP_STEP_01;
+ context->socket = socket;
+ context->cb = cb;
+ context->user_param = user_param;
+ context->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
+
+ return context;
+}
+
+static net_nfc_server_snep_op_context_t *
+_net_nfc_server_snep_create_recv_context(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ void *cb,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context = NULL;
+ net_nfc_llcp_config_info_s config;
+ net_nfc_error_e result;
+
+ if (net_nfc_controller_llcp_get_remote_config(handle,
+ &config,
+ &result) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_get_remote_config failed, [%d]",
+ result);
+ return NULL;
+ }
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ if (context == NULL)
+ return NULL;
+
+ context->handle = handle;
+ context->state = NET_NFC_LLCP_STEP_01;
+ context->socket = socket;
+ context->cb = cb;
+ context->user_param = user_param;
+ context->miu = MIN(config.miu, net_nfc_server_llcp_get_miu());
+
+ return context;
+}
+
+static void _net_nfc_server_snep_destory_context(
+ net_nfc_server_snep_op_context_t *context)
+{
+ if (context != NULL)
+ {
+ if (context->data.buffer != NULL)
+ net_nfc_util_free_data(&context->data);
+
+ _net_nfc_util_free_mem(context);
+ }
+}
+
+static void _net_nfc_server_recv_fragment_cb(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+ uint8_t *buffer;
+ uint32_t length;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_recv_fragment_cb,"
+ " socket [%x], result [%d]",socket, result);
+
+ if (context == NULL)
+ return;
+
+ context->result = result;
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("error [%d]", result);
+ context->state = NET_NFC_STATE_ERROR;
+ goto END;
+ }
+
+ if (data == NULL || data->buffer == NULL || data->length == 0)
+ {
+ DEBUG_ERR_MSG("invalid response");
+ context->state = NET_NFC_STATE_ERROR;
+ goto END;
+ }
+
+ if (context->state == NET_NFC_LLCP_STEP_01)
+ {
+ net_nfc_server_snep_msg_t *msg =
+ (net_nfc_server_snep_msg_t *)data->buffer;
+
+ if (data->length < SNEP_HEADER_LEN)
+ {
+ DEBUG_ERR_MSG("too short data, length [%d]",
+ data->length);
+ /* FIXME!!! what should I do. */
+ context->type = SNEP_RESP_BAD_REQ;
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_BUFFER_TOO_SMALL;
+ goto END;
+ }
+
+ length = htonl(msg->length);
+
+ if (length > SNEP_MAX_LEN)
+ {
+ DEBUG_ERR_MSG("too long snep message, length [%d]",
+ length);
+ if (IS_SNEP_REQ(msg->op))
+ {
+ context->type = SNEP_RESP_EXCESS_DATA;
+ }
+ else
+ {
+ context->type = SNEP_REQ_REJECT;
+ }
+ context->state = NET_NFC_LLCP_STEP_04;
+ context->result = NET_NFC_INSUFFICIENT_STORAGE;
+ goto END;
+ }
+
+ if (IS_SNEP_REQ(msg->op) &&
+ GET_MAJOR_VER(msg->version) > SNEP_MAJOR_VER)
+ {
+ DEBUG_ERR_MSG("not supported version, version [0x%02x]",
+ msg->version);
+ context->type = SNEP_RESP_UNSUPPORTED_VER;
+ context->state = NET_NFC_LLCP_STEP_04;
+ context->result = NET_NFC_NOT_SUPPORTED;
+ goto END;
+ }
+
+ if (length > 0)
+ {
+ /* buffer create */
+ net_nfc_util_alloc_data(&context->data, length);
+ if (context->data.buffer == NULL)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
+ if (IS_SNEP_REQ(msg->op))
+ {
+ context->type = SNEP_RESP_REJECT;
+ }
+ else
+ {
+ context->type = SNEP_REQ_REJECT;
+ }
+ context->state = NET_NFC_LLCP_STEP_04;
+ context->result = NET_NFC_ALLOC_FAIL;
+ goto END;
+ }
+ }
+
+ DEBUG_SERVER_MSG("incoming message, type [0x%02x], length [%d]",
+ msg->op, length);
+
+ context->type = msg->op;
+ buffer = msg->data;
+ length = data->length - SNEP_HEADER_LEN;
+ context->state = NET_NFC_LLCP_STEP_02;
+ }
+ else
+ {
+ buffer = data->buffer;
+ length = data->length;
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+
+ if (context->data.length > 0)
+ {
+ /* copy data */
+ memcpy(context->data.buffer + context->offset,
+ buffer, length);
+ context->offset += length;
+
+ DEBUG_SERVER_MSG("receive progress... [%d|%d]",
+ context->offset, context->data.length);
+
+ if (context->offset >= context->data.length)
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("receive complete... [no ndef message]");
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+ }
+
+END :
+ _net_nfc_server_snep_recv(context);
+}
+
+
+static void _net_nfc_server_recv_fragment(
+ net_nfc_server_snep_op_context_t *context)
+{
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("socket [%x] waiting data.....", context->socket);
+
+ if (net_nfc_controller_llcp_recv(
+ context->handle,
+ context->socket,
+ context->miu,
+ &result,
+ _net_nfc_server_recv_fragment_cb,
+ context) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_recv failed, [%d]", result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ _net_nfc_server_snep_recv(context);
+ }
+}
+
+
+void _net_nfc_server_snep_recv_send_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_recv_send_cb, result [%d]", result);
+
+ if (context == NULL)/* TODO */
+ return;
+
+ if (result == NET_NFC_OK)
+ context->state = NET_NFC_LLCP_STEP_03;
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [0x%x][%d]",
+ type, result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ }
+
+ _net_nfc_server_snep_recv(context);
+}
+
+void _net_nfc_server_snep_recv_send_reject_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_recv_send_reject_cb,"
+ " result [%d]", result);
+
+ if (context == NULL)/* TODO */
+ return;
+
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [0x%x][%d]",
+ type, result);
+ }
+
+ _net_nfc_server_snep_recv(context);
+}
+
+static void _net_nfc_server_snep_recv(
+ net_nfc_server_snep_op_context_t *context)
+{
+ if (context == NULL)
+ return;
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_%02d",
+ context->state - NET_NFC_LLCP_STEP_01 + 1);
+
+ /* receive fragment */
+ _net_nfc_server_recv_fragment(context);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ {
+ uint8_t op = context->type;
+
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ /* make correct request/response code */
+ op = SNEP_MAKE_PAIR_OP(op, SNEP_REQ_CONTINUE);
+
+ /* send response */
+ net_nfc_server_snep_send(
+ context->handle,
+ context->socket,
+ op,
+ NULL,
+ _net_nfc_server_snep_recv_send_cb, context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ {
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ /* send response */
+ net_nfc_server_snep_send(
+ context->handle,
+ context->socket,
+ context->type, NULL,
+ _net_nfc_server_snep_recv_send_reject_cb, context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ {
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
+
+ /* complete and invoke callback */
+ context->cb(
+ context->result,
+ context->type,
+ &context->data,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+ }
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ default :
+ DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]",
+ context->result);
+
+ context->cb(
+ context->result,
+ context->type,
+ NULL,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+
+ break;
+ }
+}
+
+static net_nfc_error_e
+net_nfc_server_snep_recv(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ _net_nfc_server_snep_operation_cb cb,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ /* create context */
+ context = _net_nfc_server_snep_create_recv_context(
+ handle,
+ socket,
+ cb,
+ user_param);
+
+ if (context != NULL)/* send response */
+ _net_nfc_server_snep_recv(context);
+ else
+ result = NET_NFC_ALLOC_FAIL;
+
+ return result;
+}
+
+static void _net_nfc_server_send_fragment_cb(
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_send_fragment_cb,"
+ " socket [%x], result [%d]",socket, result);
+
+ if (context == NULL)
+ return;
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("send progress... [%d|%d]",
+ context->offset, context->data.length);
+ if (context->offset < context->data.length)
+ {
+ if (context->state == NET_NFC_LLCP_STEP_01)
+ {
+ /* first fragment */
+ context->state = NET_NFC_LLCP_STEP_02;
+ }
+ else
+ {
+ context->state = NET_NFC_LLCP_STEP_03;
+ }
+ }
+ else
+ {
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed, [%d]",
+ result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+ _net_nfc_server_snep_send(context);
+}
+
+static void _net_nfc_server_send_fragment(
+ net_nfc_server_snep_op_context_t *context)
+{
+ data_s req_msg;
+ uint32_t remain_len;
+ net_nfc_error_e result;
+
+ if (context == NULL)
+ return;
+
+ /* calc remain buffer length */
+ remain_len = context->data.length - context->offset;
+
+ req_msg.length = (remain_len < context->miu) ? remain_len : context->miu;
+ req_msg.buffer = context->data.buffer + context->offset;
+
+ DEBUG_SERVER_MSG("try to send data, socket [%x], offset [%d],"
+ " current [%d], remain [%d]",context->socket, context->offset,
+ req_msg.length, remain_len - req_msg.length);
+
+ context->offset += req_msg.length;
+
+ if (net_nfc_controller_llcp_send(context->handle,
+ context->socket,
+ &req_msg,
+ &result,
+ _net_nfc_server_send_fragment_cb,
+ context) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed, [%d]",
+ result);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = result;
+ _net_nfc_server_snep_send(context);
+ }
+}
+
+void _net_nfc_server_snep_send_recv_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context =
+ (net_nfc_server_snep_op_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_send_recv_cb,"
+ " result [%d]", result);
+
+ if (context == NULL)/* TODO */
+ return;
+
+ DEBUG_SERVER_MSG("received message, type [%d]", type);
+
+ context->result = result;
+ context->type = type;
+
+ switch (type)
+ {
+ case SNEP_REQ_CONTINUE :
+ case SNEP_RESP_CONT :
+ context->state = NET_NFC_LLCP_STEP_03;
+ break;
+
+ case SNEP_REQ_REJECT :
+ case SNEP_RESP_REJECT :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_LLCP_SOCKET_FRAME_REJECTED;
+ break;
+
+ case SNEP_RESP_NOT_FOUND :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_NO_DATA_FOUND;
+ break;
+
+ case SNEP_RESP_EXCESS_DATA :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_INSUFFICIENT_STORAGE;
+ break;
+
+ case SNEP_RESP_BAD_REQ :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_INVALID_FORMAT;
+ break;
+
+ case SNEP_RESP_NOT_IMPLEMENT :
+ case SNEP_RESP_UNSUPPORTED_VER :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_NOT_ALLOWED_OPERATION;
+ break;
+
+ default :
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_OPERATION_FAIL;
+ break;
+ }
+
+ _net_nfc_server_snep_send(context);
+}
+
+static void _net_nfc_server_snep_send(
+ net_nfc_server_snep_op_context_t *context)
+{
+ if (context == NULL)
+ {
+ return;
+ }
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_%02d",
+ context->state - NET_NFC_LLCP_STEP_01 + 1);
+
+ /* send fragment */
+ _net_nfc_server_send_fragment(context);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ /* receive response */
+ net_nfc_server_snep_recv(
+ context->handle,
+ context->socket,
+ _net_nfc_server_snep_send_recv_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
+
+ /* complete and invoke callback */
+ context->cb(
+ context->result,
+ context->type,
+ NULL,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]",
+ context->result);
+
+ context->cb(
+ context->result,
+ context->type,
+ NULL,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+ break;
+
+ default :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
+
+ context->cb(NET_NFC_OPERATION_FAIL,
+ context->type,
+ NULL,
+ context->user_param);
+
+ _net_nfc_server_snep_destory_context(context);
+ break;
+ }
+}
+
+net_nfc_error_e net_nfc_server_snep_send(
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ uint32_t type,
+ data_s *data,
+ _net_nfc_server_snep_operation_cb cb,
+ void *user_param)
+{
+ net_nfc_server_snep_op_context_t *context;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ /* create context */
+ context = _net_nfc_server_snep_create_send_context(
+ type,
+ handle,
+ socket,
+ data,
+ cb,
+ user_param);
+
+ if (context != NULL)
+ {
+ /* send response */
+ _net_nfc_server_snep_send(context);
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
+static void _net_nfc_server_snep_server_recv_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_server_recv_cb"
+ "result [%d]", result);
+
+ if (context == NULL)
+ {
+ /* TODO */
+ return;
+ }
+
+ context->result = result;
+ context->type = type;
+
+ if (result == NET_NFC_OK && data != NULL && data->buffer != NULL)
+ {
+ DEBUG_SERVER_MSG("received message, type [%d], length [%d]",
+ type, data->length);
+
+ net_nfc_util_alloc_data(&context->data, data->length);
+ if (context->data.buffer != NULL)
+ {
+ memcpy(context->data.buffer,
+ data->buffer, data->length);
+
+ switch (type)
+ {
+ case SNEP_REQ_GET :
+ context->state = NET_NFC_LLCP_STEP_02;
+ break;
+
+ case SNEP_REQ_PUT :
+ context->state = NET_NFC_LLCP_STEP_04;
+ break;
+
+ default :
+ DEBUG_ERR_MSG("invalid request, [%d]", type);
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_NOT_ALLOWED_OPERATION;
+ break;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
+ /* TODO */
+ context->state = NET_NFC_STATE_ERROR;
+ context->result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]", result);
+ context->type = type;
+ context->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_snep_server_process(context);
+}
+
+
+static void _net_nfc_server_snep_server_send_cb(net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_server_send_cb"
+ ", result [%d]", result);
+
+ if (context == NULL)/* TODO */
+ return;
+
+ context->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("server process success. and restart....");
+
+ /* restart */
+ net_nfc_util_free_data(&context->data);
+ context->state = NET_NFC_LLCP_STEP_01;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]", result);
+ context->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_snep_server_process(context);
+}
+
+
+static void _net_nfc_server_snep_server_process(
+ net_nfc_server_snep_context_t *context)
+{
+ if (context == NULL)
+ return;
+
+ switch (context->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
+
+ /* receive request */
+ net_nfc_server_snep_recv(
+ context->handle,
+ context->socket,
+ _net_nfc_server_snep_server_recv_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ context->state = NET_NFC_LLCP_STEP_03;
+
+ if (context->cb == NULL ||
+ context->cb((net_nfc_snep_handle_h)context,
+ context->result,
+ context->type,
+ &context->data,
+ context->user_param) != NET_NFC_OK)
+ {
+ /* there is no response for GET request */
+ DEBUG_ERR_MSG("there is no response for GET request");
+
+ /* receive request */
+ net_nfc_server_snep_send(context->handle,
+ context->socket,
+ SNEP_RESP_NOT_FOUND,
+ NULL,
+ _net_nfc_server_snep_server_send_cb,
+ context);
+ }
+ break;
+
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_03");
+
+ /* receive request */
+ net_nfc_server_snep_send(context->handle,
+ context->socket,
+ SNEP_RESP_SUCCESS,
+ &context->data,
+ _net_nfc_server_snep_server_send_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_04 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_04");
+
+ if (context->cb != NULL)
+ {
+ /* complete and invoke callback */
+ context->cb(
+ (net_nfc_snep_handle_h)context,
+ NET_NFC_OK,
+ context->type,
+ &context->data,
+ context->user_param);
+ }
+
+ /* receive request */
+ net_nfc_server_snep_send(context->handle,
+ context->socket,
+ SNEP_RESP_SUCCESS,
+ NULL,
+ _net_nfc_server_snep_server_send_cb,
+ context);
+ break;
+
+ case NET_NFC_LLCP_STEP_10 : /* server error, and need to send error code to client */
+ {
+ /* FIXME : */
+ }
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ DEBUG_SERVER_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("_snep_server_recv failed, [%d]",
+ context->result);
+
+ if (context->cb != NULL)
+ {
+ context->cb((net_nfc_snep_handle_h)context,
+ context->result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+
+ /* restart?? */
+ break;
+
+ default :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_??");
+ /* TODO */
+ break;
+ }
+}
+
+
+static void _net_nfc_server_snep_clear_queue(
+ gpointer data,
+ gpointer user_data)
+{
+ net_nfc_server_snep_job_t *job = (net_nfc_server_snep_job_t *)data;
+
+ if (job != NULL)
+ {
+ if (job->cb != NULL)
+ {
+ job->cb((net_nfc_snep_handle_h)job->context,
+ NET_NFC_OPERATION_FAIL, job->type,
+ NULL, job->user_param);
+ }
+
+ if (job->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&job->data);
+ }
+
+ _net_nfc_util_free_mem(job);
+ }
+}
+
+
+static void _net_nfc_server_snep_incomming_socket_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_incomming_socket_error_cb,"
+ " socket [%x], result [%d]",socket, result);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ if (context->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&context->data);
+ }
+
+ g_queue_foreach(&context->queue,
+ _net_nfc_server_snep_clear_queue,
+ NULL);
+
+ _net_nfc_util_free_mem(context);
+}
+
+
+static void _net_nfc_server_snep_socket_error_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_socket_error_cb"
+ " socket [%x], result [%d]",socket, result);
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ if (context->cb != NULL)
+ {
+ context->cb((net_nfc_snep_handle_h)context,
+ result,
+ NET_NFC_LLCP_STOP,
+ NULL,
+ context->user_param);
+ }
+
+ /*net_nfc_controller_llcp_socket_close(socket, &result);*/
+
+ if (context->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&context->data);
+ }
+
+ g_queue_foreach(&context->queue,
+ _net_nfc_server_snep_clear_queue,
+ NULL);
+
+ _net_nfc_util_free_mem(context);
+}
+
+
+static void _net_nfc_server_snep_incoming_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+ net_nfc_server_snep_context_t *accept_context = NULL;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ DEBUG_SERVER_MSG("_net_nfc_server_snep_incoming_cb,"
+ " incoming socket [%x], result [%d]",socket, result);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("listen socket failed, [%d]", result);
+
+ goto ERROR;
+ }
+
+ /* start snep server */
+ _net_nfc_util_alloc_mem(accept_context, sizeof(*accept_context));
+
+ if (accept_context == NULL)
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ result = NET_NFC_ALLOC_FAIL;
+
+ goto ERROR;
+ }
+
+ accept_context->handle = context->handle;
+ accept_context->socket = socket;
+ accept_context->cb = context->cb;
+ accept_context->user_param = context->user_param;
+ accept_context->state = NET_NFC_LLCP_STEP_01;
+
+ result = net_nfc_server_llcp_simple_accept(handle,
+ socket,
+ _net_nfc_server_snep_incomming_socket_error_cb,
+ accept_context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_accept failed, [%d]",
+ result);
+ goto ERROR;
+ }
+
+ DEBUG_SERVER_MSG("socket [%x] accepted.. waiting for request message",
+ socket);
+
+ _net_nfc_server_snep_server_process(accept_context);
+
+ return;
+
+ERROR :
+ if (accept_context != NULL)
+ {
+ _net_nfc_util_free_mem(accept_context);
+ }
+
+ if (context->cb != NULL)
+ {
+ context->cb((net_nfc_snep_handle_h)context,
+ result,
+ context->type,
+ NULL,
+ context->user_param);
+ }
+}
+
+net_nfc_error_e net_nfc_server_snep_server(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_snep_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result;
+ net_nfc_server_snep_context_t *context = NULL;
+
+ if (handle == NULL || san == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+
+ if (context == NULL)
+ {
+ DEBUG_ERR_MSG("_create_snep_context failed");
+ result = NET_NFC_ALLOC_FAIL;
+ goto ERROR;
+ }
+ context->handle = handle;
+ context->cb = cb;
+ context->user_param = user_param;
+ context->state = NET_NFC_LLCP_STEP_01;
+
+ result = net_nfc_server_llcp_simple_server(handle,
+ san,
+ sap,
+ _net_nfc_server_snep_incoming_cb,
+ _net_nfc_server_snep_socket_error_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_server failed, [%d]",
+ result);
+ goto ERROR;
+ }
+
+ DEBUG_SERVER_MSG("start snep server, san [%s], sap [%d]",
+ san, sap);
+ return result;
+
+ERROR :
+ if (context != NULL)
+ _net_nfc_util_free_mem(context);
+
+ return result;
+}
+
+net_nfc_error_e net_nfc_server_snep_server_send_get_response(
+ net_nfc_snep_handle_h snep_handle,
+ data_s *data)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)snep_handle;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (context == NULL/* && check valid handle */)
+ {
+ DEBUG_ERR_MSG("invalid handle");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ DEBUG_SERVER_MSG("send get response, socket [%x]", context->socket);
+
+ /* check correct status */
+ if (context->type == SNEP_REQ_GET)
+ {
+ if (context->data.buffer != NULL)
+ net_nfc_util_free_data(&context->data);
+
+ if (data != NULL)
+ {
+ context->type = SNEP_RESP_SUCCESS;
+
+ if (net_nfc_util_alloc_data(&context->data, data->length) == true)
+ {
+ memcpy(context->data.buffer, data->buffer,
+ data->length);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ else
+ {
+ /* not found */
+ context->type = SNEP_RESP_NOT_FOUND;
+ }
+
+ _net_nfc_server_snep_server_process(context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("incorrect handle state");
+ result = NET_NFC_INVALID_STATE;
+ }
+
+ return result;
+}
+
+static void _net_nfc_server_snep_client_send_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_job_t*job =
+ (net_nfc_server_snep_job_t *)user_param;
+
+ if (job == NULL)
+ {
+ /* TODO */
+ return;
+ }
+
+ job->type = type;
+ job->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ job->state = NET_NFC_LLCP_STEP_02;
+
+ net_nfc_util_free_data(&job->data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_server_snep_send failed, [%d]", result);
+ job->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_snep_client_process(job);
+}
+
+static void _net_nfc_server_snep_client_recv_cb(
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_job_t *job =
+ (net_nfc_server_snep_job_t *)user_param;
+
+ if (job == NULL)
+ {
+ /* TODO */
+ return;
+ }
+
+ job->type = type;
+ job->result = result;
+
+ if (result == NET_NFC_OK)
+ {
+ if (type == SNEP_RESP_SUCCESS)
+ {
+ job->state = NET_NFC_LLCP_STEP_RETURN;
+ if (data != NULL && data->buffer != NULL)
+ {
+ net_nfc_util_alloc_data(&job->data, data->length);
+ if (job->data.buffer != NULL)
+ {
+ memcpy(job->data.buffer, data->buffer,
+ data->length);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_alloc_data failed");
+ job->state = NET_NFC_STATE_ERROR;
+ job->result = NET_NFC_ALLOC_FAIL;
+ }
+ }
+ }
+ else
+ {
+ /* TODO */
+ DEBUG_ERR_MSG("invalid request, [0x%x]", type);
+ job->state = NET_NFC_STATE_ERROR;
+ job->result = NET_NFC_NOT_ALLOWED_OPERATION;
+ }
+ }
+ else
+ {
+
+ DEBUG_ERR_MSG("net_nfc_server_snep_recv failed, [%d]", result);
+ job->state = NET_NFC_STATE_ERROR;
+ }
+
+ _net_nfc_server_snep_client_process(job);
+}
+
+
+static void _net_nfc_server_snep_client_do_job(net_nfc_server_snep_context_t *context)
+{
+ if (context->state == NET_NFC_LLCP_IDLE &&
+ g_queue_is_empty(&context->queue) == false) {
+ net_nfc_server_snep_job_t *job;
+
+ job = g_queue_pop_head(&context->queue);
+ if (job != NULL) {
+ context->state = NET_NFC_LLCP_STEP_01;
+ job->state = NET_NFC_LLCP_STEP_01;
+ _net_nfc_server_snep_client_process(job);
+ }
+ }
+}
+
+static void _net_nfc_server_snep_client_process(
+ net_nfc_server_snep_job_t *job)
+{
+ bool finish = false;
+
+ if (job == NULL)
+ {
+ return;
+ }
+
+ switch (job->state)
+ {
+ case NET_NFC_LLCP_STEP_01 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_01");
+
+ /* send request */
+ net_nfc_server_snep_send(job->handle,
+ job->socket,
+ job->type,
+ &job->data,
+ _net_nfc_server_snep_client_send_cb,
+ job);
+ break;
+
+ case NET_NFC_LLCP_STEP_02 :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_02");
+
+ /* receive response */
+ net_nfc_server_snep_recv(job->handle,
+ job->socket,
+ _net_nfc_server_snep_client_recv_cb,
+ job);
+ break;
+
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_SERVER_MSG("NET_NFC_LLCP_STEP_RETURN");
+
+ /* complete and invoke callback */
+ if (job->cb != NULL)
+ {
+ job->cb((net_nfc_snep_handle_h)job->context,
+ NET_NFC_OK,
+ job->type,
+ &job->data,
+ job->user_param);
+ }
+
+ /* finish job */
+ finish = true;
+ break;
+
+ case NET_NFC_STATE_ERROR :
+ default :
+ DEBUG_ERR_MSG("NET_NFC_STATE_ERROR");
+
+ /* error, invoke callback */
+ DEBUG_ERR_MSG("_snep_server_send failed, [%d]",
+ job->result);
+ if (job->cb != NULL)
+ {
+ job->cb((net_nfc_snep_handle_h)job->context,
+ job->result,
+ job->type,
+ &job->data,
+ job->user_param);
+ }
+
+ /* finish job */
+ finish = true;
+ break;
+ }
+
+ if (finish == true)
+ {
+ net_nfc_server_snep_context_t *context = job->context;
+
+ if (job->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&job->data);
+ }
+
+ _net_nfc_util_free_mem(job);
+
+ context->state = NET_NFC_LLCP_IDLE;
+
+ _net_nfc_server_snep_client_do_job(context);
+ }
+}
+
+static void _net_nfc_server_snep_connected_cb(
+ net_nfc_error_e result,
+ net_nfc_target_handle_s *handle,
+ net_nfc_llcp_socket_t socket,
+ data_s *data,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)user_param;
+
+ if (context == NULL)
+ {
+ return;
+ }
+
+ context->socket = socket;
+
+ if (result == NET_NFC_OK)
+ {
+ /* start snep client */
+ DEBUG_SERVER_MSG("socket [%x] connected. send message",
+ socket);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("connect socket failed, [%d]", result);
+ }
+
+ if (context->cb != NULL)
+ {
+ context->cb((net_nfc_snep_handle_h)context,
+ result,
+ NET_NFC_LLCP_START,
+ NULL,
+ context->user_param);
+ }
+}
+
+net_nfc_error_e net_nfc_server_snep_client(
+ net_nfc_target_handle_s *handle,
+ const char *san,
+ sap_t sap,
+ net_nfc_server_snep_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result;
+ net_nfc_server_snep_context_t *context = NULL;
+
+ if (handle == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context == NULL)
+ {
+ DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
+ result = NET_NFC_ALLOC_FAIL;
+
+ goto ERROR;
+ }
+ context->handle = handle;
+ context->cb = cb;
+ context->user_param = user_param;
+
+ result = net_nfc_server_llcp_simple_client(handle,
+ san,
+ sap,
+ _net_nfc_server_snep_connected_cb,
+ _net_nfc_server_snep_socket_error_cb,
+ context);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_llcp_simple_client failed, [%d]",
+ result);
+
+ goto ERROR;
+ }
+ if (san != NULL)
+ DEBUG_SERVER_MSG("start snep client, san [%s]",
+ san);
+ else
+ DEBUG_SERVER_MSG("start snep client, sap [%d]",
+ sap);
+
+ return result;
+
+ERROR :
+ if (context != NULL)
+ {
+ if (context->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&context->data);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+
+ return result;
+}
+
+
+net_nfc_error_e net_nfc_server_snep_client_request(
+ net_nfc_snep_handle_h snep,
+ uint8_t type,
+ data_s *data,
+ net_nfc_server_snep_cb cb,
+ void *user_param)
+{
+ net_nfc_server_snep_context_t *context = (net_nfc_server_snep_context_t *)snep;
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_server_snep_job_t *job;
+
+ if (context == NULL || data == NULL || data->buffer == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ /* check type */
+ _net_nfc_util_alloc_mem(job, sizeof(*job));
+ if (job != NULL)
+ {
+ net_nfc_util_alloc_data(&job->data, data->length);
+ if (job->data.buffer != NULL)
+ {
+ memcpy(job->data.buffer, data->buffer, data->length);
+ }
+ job->type = type;
+ job->cb = cb;
+ job->user_param = user_param;
+
+ job->context = context;
+ job->handle = context->handle;
+ job->socket = context->socket;
+
+ g_queue_push_tail(&context->queue, job);
+ }
+ else
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ INFO_MSG("enqueued jobs [%d]", g_queue_get_length(&context->queue));
+
+ /* if client is idle, starts sending request */
+ if (context->state == NET_NFC_LLCP_IDLE)
+ {
+ _net_nfc_server_snep_client_do_job(context);
+ } else {
+ INFO_MSG("client is working. this job will be enqueued");
+ }
+
+ return result;
+}
+
+static net_nfc_error_e _net_nfc_server_default_server_cb_(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ if (result != NET_NFC_OK || data == NULL || data->buffer == NULL)
+ {
+ /* restart */
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ switch (type)
+ {
+ case SNEP_REQ_GET:
+ {
+ net_nfc_server_snep_get_msg_t *msg =
+ (net_nfc_server_snep_get_msg_t *)data->buffer;
+
+
+ uint32_t max_len = htonl(msg->length);
+ data_s get_msg = { msg->data,data->length - sizeof(msg->length)};
+
+ DEBUG_SERVER_MSG("GET : acceptable max_len [%d], message [%d]",
+ max_len, data->length - sizeof(msg->length));
+
+
+ if (_net_nfc_server_snep_process_get_response_cb(handle, &get_msg, max_len))
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ result = NET_NFC_NOT_SUPPORTED;
+ }
+ }
+ break;
+
+ case SNEP_REQ_PUT :
+ {
+ net_nfc_server_p2p_received(data);
+ net_nfc_app_util_process_ndef(data);;
+
+ result = NET_NFC_OK;
+ }
+ break;
+
+ default :
+ DEBUG_ERR_MSG("error [%d]", result);
+ break;
+ }
+
+ return result;
+}
+
+
+static net_nfc_error_e _net_nfc_server_default_client_cb_(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ _net_nfc_server_snep_service_context_t *context =
+ (_net_nfc_server_snep_service_context_t*)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p]",
+ type, result, data);
+
+ if (user_param == NULL)
+ return NET_NFC_NULL_PARAMETER;;
+
+ switch (type)
+ {
+ case SNEP_RESP_SUCCESS :
+ case SNEP_RESP_BAD_REQ :
+ case SNEP_RESP_EXCESS_DATA :
+ case SNEP_RESP_NOT_FOUND :
+ case SNEP_RESP_NOT_IMPLEMENT :
+ case SNEP_RESP_REJECT :
+ case SNEP_RESP_UNSUPPORTED_VER :
+ context = (_net_nfc_server_snep_service_context_t *)user_param;
+
+ net_nfc_server_p2p_data_sent(result,
+ context->user_param);
+
+ _net_nfc_util_free_mem(context);
+ break;
+
+ default :
+ DEBUG_ERR_MSG("error [%d]", result);
+ break;
+ }
+
+ return result;
+}
+
+
+static net_nfc_error_e _net_nfc_server_default_client_connected_cb_(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ _net_nfc_server_snep_service_context_t *context =
+ (_net_nfc_server_snep_service_context_t *)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ if (context == NULL)
+ {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (result == NET_NFC_OK)
+ {
+ net_nfc_server_snep_client_request(handle,
+ context->type,
+ &context->data,
+ _net_nfc_server_default_client_cb_,
+ context);
+ }
+ else
+ {
+ if (context->data.buffer != NULL)
+ {
+ net_nfc_util_free_data(&context->data);
+ }
+ _net_nfc_util_free_mem(context);
+ }
+
+ return result;
+}
+
+
+net_nfc_error_e net_nfc_server_snep_default_server_start(
+ net_nfc_target_handle_s *handle)
+{
+ /* start default snep server, register your callback */
+ return net_nfc_server_snep_server(handle,
+ SNEP_SAN,
+ SNEP_SAP,
+ _net_nfc_server_default_server_cb_,
+ (void *)1234);
+}
+
+
+net_nfc_error_e net_nfc_server_snep_default_client_start(
+ net_nfc_target_handle_s *handle,
+ int type,
+ data_s *data,
+ int client,
+ void *user_param)
+{
+ _net_nfc_server_snep_service_context_t *context = NULL;
+
+ _net_nfc_util_alloc_mem(context, sizeof(*context));
+ if (context != NULL)
+ {
+ context->handle = handle;
+ context->client = client;
+ context->user_param = user_param;
+ context->type = type;
+ net_nfc_util_alloc_data(&context->data, data->length);
+ if (context->data.buffer != NULL)
+ {
+ memcpy(context->data.buffer, data->buffer,
+ data->length);
+ context->data.length = data->length;
+ }
+ /* start default snep client, register your callback */
+ return net_nfc_server_snep_client(handle,
+ SNEP_SAN,
+ SNEP_SAP,
+ _net_nfc_server_default_client_connected_cb_,
+ context);
+ }
+ else
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+}
+
+net_nfc_error_e
+net_nfc_server_snep_default_server_register_get_response_cb(
+ net_nfc_server_snep_listen_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result;
+
+ if (_net_nfc_server_snep_add_get_response_cb(cb, user_param) == true)
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ result = NET_NFC_ALREADY_REGISTERED;
+ }
+
+ return result;
+}
+
+net_nfc_error_e
+net_nfc_server_snep_default_server_unregister_get_response_cb(
+ net_nfc_server_snep_listen_cb cb)
+{
+ _net_nfc_server_snep_del_get_response_cb(cb);
+
+ return NET_NFC_OK;
+}
+
+net_nfc_error_e net_nfc_server_snep_default_server_send_get_response(
+ net_nfc_snep_handle_h snep_handle, data_s *data)
+{
+ net_nfc_server_snep_context_t *context =
+ (net_nfc_server_snep_context_t *)snep_handle;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (context == NULL/* && check valid handle */)
+ {
+ DEBUG_ERR_MSG("invalid handle");
+ return NET_NFC_INVALID_PARAM;
+ }
+
+ /* check correct status */
+ if (context->type == SNEP_REQ_GET &&
+ context->state == NET_NFC_LLCP_STEP_03)
+ {
+ net_nfc_server_snep_server_send_get_response(snep_handle, data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("incorrect handle state");
+ result = NET_NFC_INVALID_STATE;
+ }
+
+ return result;
+}
+
+static void _snep_default_activate_cb(int event,
+ net_nfc_target_handle_s *handle,
+ uint32_t sap, const char *san, void *user_param)
+{
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
+ event, handle, sap, san);
+
+ if (event == NET_NFC_LLCP_START) {
+ /* start snep server */
+ result = net_nfc_server_snep_server(handle, (char *)san, sap,
+ _net_nfc_server_default_server_cb_, user_param);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_service_snep_server failed, [%d]",
+ result);
+ }
+ } else if (event == NET_NFC_LLCP_UNREGISTERED) {
+ /* unregister server, do nothing */
+ }
+}
+
+net_nfc_error_e net_nfc_server_snep_default_server_register()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default snep server */
+ return net_nfc_server_llcp_register_service(id,
+ SNEP_SAP,
+ SNEP_SAN,
+ _snep_default_activate_cb,
+ NULL);
+}
+
+net_nfc_error_e net_nfc_server_snep_default_server_unregister()
+{
+ char id[20];
+
+ /* TODO : make id, */
+ snprintf(id, sizeof(id), "%d", getpid());
+
+ /* start default snep server */
+ return net_nfc_server_llcp_unregister_service(id,
+ SNEP_SAP,
+ SNEP_SAN);
+}
+
+net_nfc_error_e net_nfc_server_snep_parse_get_request(data_s *request,
+ size_t *max_len, data_s *message)
+{
+ net_nfc_server_snep_msg_t *msg = NULL;
+
+ if (request == NULL || request->buffer == NULL ||
+ request->length == 0 || max_len == NULL || message == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ msg = (net_nfc_server_snep_msg_t *)request->buffer;
+
+ *max_len = htonl(msg->length);
+
+ message->buffer = msg->data;
+ message->length = request->length - sizeof(msg->length);
+
+ DEBUG_SERVER_MSG("GET : acceptable max_len [%d], message [%d]",
+ *max_len, request->length - sizeof(msg->length));
+
+ return NET_NFC_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <vconf.h>
+#include <tapi_common.h>
+#include <ITapiSim.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_manager.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context_internal.h"
+#include "net_nfc_server_manager.h"
+#include "net_nfc_server_se.h"
+#include "net_nfc_app_util_internal.h"
+
+
+typedef struct _nfc_se_setting_t
+{
+ bool busy;
+ uint8_t type;
+ uint8_t mode;
+}
+net_nfc_server_se_setting_t;
+
+
+static NetNfcGDbusSecureElement *se_skeleton = NULL;
+#if 0
+static uint8_t gdbus_se_prev_type = SECURE_ELEMENT_TYPE_INVALID;
+static uint8_t gdbus_se_prev_mode = SECURE_ELEMENT_OFF_MODE;
+#endif
+static net_nfc_server_se_setting_t gdbus_se_setting;
+
+/* TODO : make a list for handles */
+static TapiHandle *gdbus_uicc_handle;
+static net_nfc_target_handle_s *gdbus_ese_handle;
+
+/* server_side */
+typedef struct _ServerSeData ServerSeData;
+
+struct _ServerSeData
+{
+ data_s aid;
+ data_s param;
+ guint event;
+};
+
+typedef struct _SeDataSeType SeDataSeType;
+
+struct _SeDataSeType
+{
+ NetNfcGDbusSecureElement *object;
+ GDBusMethodInvocation *invocation;
+ gint se_type;
+};
+
+
+typedef struct _SeDataHandle SeDataHandle;
+
+struct _SeDataHandle
+{
+ NetNfcGDbusSecureElement *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s* handle;
+};
+
+typedef struct _SeDataApdu SeDataApdu;
+
+struct _SeDataApdu
+{
+ NetNfcGDbusSecureElement *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s* handle;
+ GVariant *data;
+};
+
+static void se_close_secure_element_thread_func(gpointer user_data);
+
+static void se_get_atr_thread_func(gpointer user_data);
+
+static void se_open_secure_element_thread_func(gpointer user_data);
+
+static void se_send_apdu_thread_func(gpointer user_data);
+
+static void se_set_data_thread_func(gpointer user_data);
+
+static gboolean se_handle_close_secure_element(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *smack_privilege);
+
+static gboolean se_handle_get_atr(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *smack_privilege);
+
+
+static gboolean se_handle_open_secure_element(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ gint arg_type,
+ GVariant *smack_privilege);
+
+
+static gboolean se_handle_send_apdu(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant* apdudata,
+ GVariant *smack_privilege);
+
+static gboolean se_handle_set(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ gint arg_type,
+ GVariant *smack_privilege);
+
+
+uint8_t net_nfc_server_se_get_se_type()
+{
+ return gdbus_se_setting.type;
+}
+
+uint8_t net_nfc_server_se_get_se_mode()
+{
+ return gdbus_se_setting.mode;
+}
+
+static void net_nfc_server_se_set_se_type(uint8_t type)
+{
+ gdbus_se_setting.type = type;
+}
+
+static void net_nfc_server_se_set_se_mode(uint8_t mode)
+{
+ gdbus_se_setting.mode = mode;
+}
+
+
+/* eSE functions */
+static bool net_nfc_server_se_is_ese_handle(net_nfc_target_handle_s *handle)
+{
+ return (gdbus_ese_handle != NULL &&
+ gdbus_ese_handle == handle);
+}
+
+static void net_nfc_server_se_set_current_ese_handle(
+ net_nfc_target_handle_s *handle)
+{
+ gdbus_ese_handle = handle;
+}
+
+static net_nfc_target_handle_s *net_nfc_server_se_open_ese()
+{
+ if (gdbus_ese_handle == NULL) {
+ net_nfc_error_e result;
+ net_nfc_target_handle_s *handle;
+
+ if (net_nfc_controller_secure_element_open(
+ SECURE_ELEMENT_TYPE_ESE,
+ &handle, &result) == true)
+ {
+ net_nfc_server_se_set_current_ese_handle(handle);
+
+ DEBUG_SERVER_MSG("handle [%p]", handle);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_secure_element_open failed [%d]",
+ result);
+ }
+ }
+
+ return gdbus_ese_handle;
+}
+
+static net_nfc_error_e net_nfc_server_se_close_ese()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (gdbus_ese_handle != NULL &&
+ net_nfc_server_gdbus_is_server_busy() == false) {
+ if (net_nfc_controller_secure_element_close(
+ gdbus_ese_handle,
+ &result) == false)
+ {
+ net_nfc_controller_exception_handler();
+ }
+ net_nfc_server_se_set_current_ese_handle(NULL);
+ }
+
+ return result;
+}
+
+
+/* UICC functions */
+static TelSimCardStatus_t _se_uicc_check_state(TapiHandle *handle)
+{
+ TelSimCardStatus_t state = TAPI_SIM_STATUS_UNKNOWN;
+ int b_card_changed = 0;
+ int error;
+
+ error = tel_get_sim_init_info(handle,
+ &state,
+ &b_card_changed);
+ if (error != 0)
+ {
+ DEBUG_ERR_MSG("error = [%d]", error);
+ }
+
+ DEBUG_SERVER_MSG("current sim init state = [%d]", state);
+
+ return state;
+}
+
+static void _se_uicc_status_noti_cb(TapiHandle *handle,
+ const char *noti_id,
+ void *data,
+ void *user_data)
+{
+ TelSimCardStatus_t *status = (TelSimCardStatus_t *)data;
+
+ DEBUG_SERVER_MSG("_se_uicc_status_noti_cb");
+
+ switch (*status) {
+ case TAPI_SIM_STATUS_SIM_INIT_COMPLETED :
+ if (gdbus_se_setting.busy == true)
+ {
+ net_nfc_error_e result;
+
+ DEBUG_SERVER_MSG("TAPI_SIM_STATUS_SIM_INIT_COMPLETED");
+
+ gdbus_se_setting.busy = false;
+
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_VIRTUAL_MODE, &result);
+ if (result == NET_NFC_OK) {
+ DEBUG_SERVER_MSG(
+ "changed to SECURE_ELEMENT_TYPE_UICC");
+ net_nfc_server_se_set_se_type(
+ SECURE_ELEMENT_TYPE_UICC);
+ net_nfc_server_se_set_se_mode(
+ SECURE_ELEMENT_VIRTUAL_MODE);
+ if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
+ VCONFKEY_NFC_SE_TYPE_UICC) != 0) {
+ DEBUG_ERR_MSG("vconf_set_int failed");
+ }
+ } else {
+ DEBUG_ERR_MSG(
+ "SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]",
+ result);
+ }
+ }
+ break;
+
+ case TAPI_SIM_STATUS_CARD_REMOVED :
+ DEBUG_SERVER_MSG("TAPI_SIM_STATUS_CARD_REMOVED");
+ /* do something */
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void _se_uicc_init(void)
+{
+ char **cpList;
+
+ cpList = tel_get_cp_name_list();
+ if (cpList != NULL) {
+ gdbus_uicc_handle = tel_init(cpList[0]);
+ if (gdbus_uicc_handle != NULL) {
+ tel_register_noti_event(gdbus_uicc_handle,
+ TAPI_NOTI_SIM_STATUS,
+ _se_uicc_status_noti_cb,
+ NULL);
+
+ } else {
+ DEBUG_ERR_MSG("tel_init() failed");
+ }
+ } else {
+ DEBUG_ERR_MSG("tel_get_cp_name_list() failed");
+ }
+}
+
+static void _se_uicc_deinit()
+{
+ tel_deregister_noti_event(gdbus_uicc_handle,
+ TAPI_NOTI_SIM_STATUS);
+
+ tel_deinit(gdbus_uicc_handle);
+
+ gdbus_uicc_handle = NULL;
+}
+
+
+static net_nfc_target_handle_s *_se_uicc_open(void)
+{
+ net_nfc_target_handle_s *result = NULL;
+
+ if (gdbus_uicc_handle != NULL) {
+ TelSimCardStatus_t status;
+
+ status = _se_uicc_check_state(gdbus_uicc_handle);
+ if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
+ result = (net_nfc_target_handle_s *)gdbus_uicc_handle;
+ }
+ }
+
+ return result;
+}
+
+static bool _se_is_uicc_handle(net_nfc_target_handle_s *handle)
+{
+ return (gdbus_uicc_handle != NULL &&
+ (TapiHandle *)handle == gdbus_uicc_handle);
+}
+
+static void _se_uicc_close(net_nfc_target_handle_s *handle)
+{
+}
+
+/* SE Functions */
+net_nfc_error_e net_nfc_server_se_change_se(uint8_t type)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ switch (type) {
+ case SECURE_ELEMENT_TYPE_UICC :
+ if (gdbus_se_setting.busy == false) {
+ TelSimCardStatus_t state;
+
+ /*turn off ESE*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_ESE,
+ SECURE_ELEMENT_OFF_MODE,
+ &result);
+
+ state = _se_uicc_check_state(gdbus_uicc_handle);
+ if (state == TAPI_SIM_STATUS_SIM_INIT_COMPLETED ||
+ state == TAPI_SIM_STATUS_CARD_NOT_PRESENT ||
+ state == TAPI_SIM_STATUS_CARD_REMOVED) {
+ /*turn on UICC*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_VIRTUAL_MODE, &result);
+ if (result == NET_NFC_OK) {
+ DEBUG_SERVER_MSG(
+ "changed to SECURE_ELEMENT_TYPE_UICC");
+
+ net_nfc_server_se_set_se_type(
+ SECURE_ELEMENT_TYPE_UICC);
+ net_nfc_server_se_set_se_mode(
+ SECURE_ELEMENT_VIRTUAL_MODE);
+
+ if (vconf_set_int(
+ VCONFKEY_NFC_SE_TYPE,
+ VCONFKEY_NFC_SE_TYPE_UICC) != 0)
+ {
+ DEBUG_ERR_MSG("vconf_set_int failed");
+ }
+ } else {
+ DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]",
+ result);
+ }
+ } else {
+ DEBUG_SERVER_MSG("UICC is not ready. waiting UICC event");
+
+ gdbus_se_setting.busy = true;
+ }
+ } else {
+ DEBUG_SERVER_MSG("Previous request is processing.");
+
+ result = NET_NFC_BUSY;
+ }
+ break;
+
+ case SECURE_ELEMENT_TYPE_ESE :
+ /*turn off UICC*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_OFF_MODE,
+ &result);
+
+ /*turn on ESE*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_ESE,
+ SECURE_ELEMENT_VIRTUAL_MODE,
+ &result);
+
+ if (result == NET_NFC_OK) {
+ DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_ESE");
+
+ net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_ESE);
+ net_nfc_server_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE);
+
+ if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
+ VCONFKEY_NFC_SE_TYPE_ESE) != 0) {
+ DEBUG_ERR_MSG("vconf_set_int failed");
+ }
+ } else {
+ DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result);
+ }
+ break;
+
+ default:
+ {
+ net_nfc_error_e result_ese, result_uicc;
+
+ net_nfc_server_se_set_se_type(
+ SECURE_ELEMENT_TYPE_INVALID);
+ net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE);
+
+ /*turn off ESE*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_ESE,
+ SECURE_ELEMENT_OFF_MODE,
+ &result_ese);
+
+ /*turn off UICC*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_OFF_MODE,
+ &result_uicc);
+
+ if (result_ese != NET_NFC_INVALID_HANDLE
+ && result_uicc != NET_NFC_INVALID_HANDLE) {
+ DEBUG_SERVER_MSG("SE off all");
+ if (vconf_set_int(VCONFKEY_NFC_SE_TYPE,
+ VCONFKEY_NFC_SE_TYPE_NONE) != 0) {
+ DEBUG_ERR_MSG("vconf_set_int failed");
+ }
+
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ DEBUG_ERR_MSG("ALL OFF failed, ese [%d], uicc [%d]",result_ese, result_uicc);
+
+ result = NET_NFC_INVALID_HANDLE;
+ }
+ }
+ break;
+ }
+
+ return result;
+}
+
+static void se_close_secure_element_thread_func(gpointer user_data)
+{
+ SeDataHandle *detail = (SeDataHandle *)user_data;
+ net_nfc_error_e result;
+
+ g_assert(detail != NULL);
+ g_assert(detail->object != NULL);
+ g_assert(detail->invocation != NULL);
+
+ if (_se_is_uicc_handle(detail->handle) == true)
+ {
+ _se_uicc_close(detail->handle);
+
+ result = NET_NFC_OK;
+ }
+ else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
+ {
+ /* decrease client reference count */
+ net_nfc_server_gdbus_decrease_se_count(
+ g_dbus_method_invocation_get_sender(
+ detail->invocation));
+
+ result = net_nfc_server_se_close_ese();
+ }
+ else
+ {
+ result = NET_NFC_INVALID_HANDLE;
+ }
+#if 0
+ if ((gdbus_se_prev_type != net_nfc_server_se_get_se_type()) ||
+ (gdbus_se_prev_mode != net_nfc_server_se_get_se_mode()))
+ {
+ /*return back se mode*/
+ net_nfc_controller_set_secure_element_mode(gdbus_se_prev_type,
+ gdbus_se_prev_mode, &result);
+
+ net_nfc_server_se_set_se_type(gdbus_se_prev_type);
+ net_nfc_server_se_set_se_mode(gdbus_se_prev_mode);
+ }
+#endif
+ net_nfc_gdbus_secure_element_complete_close_secure_element(
+ detail->object, detail->invocation, result);
+
+ g_object_unref(detail->invocation);
+ g_object_unref(detail->object);
+
+ g_free(detail);
+
+ /* shutdown process if it doesn't need */
+ if (net_nfc_server_manager_get_active() == false &&
+ net_nfc_server_gdbus_is_server_busy() == false) {
+ net_nfc_manager_quit();
+ }
+}
+
+static gboolean se_handle_close_secure_element(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *smack_privilege)
+{
+ SeDataHandle *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataHandle, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->handle = (net_nfc_target_handle_s *)arg_handle;
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_close_secure_element_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void se_get_atr_thread_func(gpointer user_data)
+{
+ SeDataHandle *detail = (SeDataHandle *)user_data;
+ data_s *atr = NULL;
+ GVariant *data;
+ net_nfc_error_e result;
+
+ g_assert(detail != NULL);
+ g_assert(detail->object != NULL);
+ g_assert(detail->invocation != NULL);
+
+ if (_se_is_uicc_handle(detail->handle) == true)
+ {
+ result = NET_NFC_NOT_SUPPORTED;
+ }
+ else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
+ {
+ net_nfc_controller_secure_element_get_atr(detail->handle, &atr,
+ &result);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("invalid se handle");
+
+ result = NET_NFC_INVALID_HANDLE;
+ }
+
+ data = net_nfc_util_gdbus_data_to_variant(atr);
+
+ net_nfc_gdbus_secure_element_complete_get_atr(
+ detail->object,
+ detail->invocation,
+ result,
+ data);
+
+ if (atr != NULL) {
+ net_nfc_util_free_data(atr);
+ g_free(atr);
+ }
+
+ g_object_unref(detail->invocation);
+ g_object_unref(detail->object);
+
+ g_free(detail);
+}
+
+static gboolean se_handle_get_atr(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *smack_privilege)
+{
+ SeDataHandle *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataHandle, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->handle = (net_nfc_target_handle_s *)arg_handle;
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_get_atr_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void se_open_secure_element_thread_func(gpointer user_data)
+{
+ SeDataSeType *detail = (SeDataSeType *)user_data;
+ net_nfc_target_handle_s *handle = NULL;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(detail != NULL);
+ g_assert(detail->object != NULL);
+ g_assert(detail->invocation != NULL);
+
+#if 0 /* opening SE doesn't affect card emulation */
+ gdbus_se_prev_type = net_nfc_server_se_get_se_type();
+ gdbus_se_prev_mode = net_nfc_server_se_get_se_mode();
+#endif
+
+ if (detail->se_type == SECURE_ELEMENT_TYPE_UICC)
+ {
+#if 0 /* opening SE doesn't affect card emulation */
+ /*off ESE*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_ESE,
+ SECURE_ELEMENT_OFF_MODE, &result);
+
+ /*Off UICC. UICC SHOULD not be detected by external reader when
+ being communicated in internal process*/
+ net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_OFF_MODE, &result);
+
+ net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_UICC);
+ net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE);
+#endif
+ handle = (net_nfc_target_handle_s *)_se_uicc_open();
+ if (handle != NULL)
+ {
+ result = NET_NFC_OK;
+ }
+ else
+ {
+ result = NET_NFC_INVALID_STATE;
+ handle = NULL;
+ }
+ }
+ else if (detail->se_type == SECURE_ELEMENT_TYPE_ESE)
+ {
+#if 0 /* opening SE doesn't affect card emulation */
+ /*off UICC*/
+ net_nfc_controller_set_secure_element_mode(
+ SECURE_ELEMENT_TYPE_UICC,
+ SECURE_ELEMENT_OFF_MODE, &result);
+#endif
+ handle = net_nfc_server_se_open_ese();
+ if (handle != NULL)
+ {
+ result = NET_NFC_OK;
+#if 0 /* opening SE doesn't affect card emulation */
+ net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_ESE);
+ net_nfc_server_se_set_se_mode(SECURE_ELEMENT_WIRED_MODE);
+
+ net_nfc_server_se_set_current_ese_handle(handle);
+#endif
+ DEBUG_SERVER_MSG("handle [%p]", handle);
+
+ /* increase client reference count */
+ net_nfc_server_gdbus_increase_se_count(
+ g_dbus_method_invocation_get_sender(
+ detail->invocation));
+ }
+ else
+ {
+ result = NET_NFC_INVALID_STATE;
+ handle = NULL;
+ }
+ }
+ else
+ {
+ result = NET_NFC_INVALID_PARAM;
+ handle = NULL;
+ }
+
+ net_nfc_gdbus_secure_element_complete_open_secure_element(
+ detail->object,
+ detail->invocation,
+ result,
+ (guint)handle);
+
+ g_object_unref(detail->invocation);
+ g_object_unref(detail->object);
+
+ g_free(detail);
+}
+
+static gboolean se_handle_open_secure_element(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ gint arg_type,
+ GVariant *smack_privilege)
+{
+ SeDataSeType *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataSeType, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->se_type= arg_type;
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_open_secure_element_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void se_send_apdu_thread_func(gpointer user_data)
+{
+ SeDataApdu *detail = (SeDataApdu *)user_data;
+ data_s apdu_data = { NULL, 0 };
+ data_s *response = NULL;
+ net_nfc_error_e result;
+ GVariant *rspdata = NULL;
+ bool ret;
+
+ g_assert(detail != NULL);
+ g_assert(detail->object != NULL);
+ g_assert(detail->invocation != NULL);
+
+ net_nfc_util_gdbus_variant_to_data_s(detail->data, &apdu_data);
+
+ if (_se_is_uicc_handle(detail->handle) == true)
+ {
+ result = NET_NFC_NOT_SUPPORTED;
+ }
+ else if (net_nfc_server_se_is_ese_handle(detail->handle) == true)
+ {
+ ret = net_nfc_controller_secure_element_send_apdu(
+ detail->handle, &apdu_data, &response, &result);
+ }
+ else
+ {
+ result = NET_NFC_INVALID_HANDLE;
+ }
+
+ rspdata = net_nfc_util_gdbus_data_to_variant(response);
+
+ net_nfc_gdbus_secure_element_complete_send_apdu(
+ detail->object,
+ detail->invocation,
+ result,
+ rspdata);
+
+ if (response != NULL)
+ {
+ net_nfc_util_free_data(response);
+ g_free(response);
+ }
+
+ net_nfc_util_free_data(&apdu_data);
+
+ g_variant_unref(detail->data);
+
+ g_object_unref(detail->invocation);
+ g_object_unref(detail->object);
+
+ g_free(detail);
+}
+
+static gboolean se_handle_send_apdu(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ GVariant *apdudata,
+ GVariant *smack_privilege)
+{
+ SeDataApdu *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataApdu, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->handle = (net_nfc_target_handle_s *)arg_handle;
+ data->data = g_variant_ref(apdudata);
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_send_apdu_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_variant_unref(data->data);
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void se_set_data_thread_func(gpointer user_data)
+{
+ SeDataSeType *data = (SeDataSeType *)user_data;
+ gboolean isTypeChanged = FALSE;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(data != NULL);
+ g_assert(data->object != NULL);
+ g_assert(data->invocation != NULL);
+
+ if (data->se_type != net_nfc_server_se_get_se_type())
+ {
+ result = net_nfc_server_se_change_se(data->se_type);
+ isTypeChanged = TRUE;
+ }
+
+ net_nfc_gdbus_secure_element_complete_set(data->object,
+ data->invocation, result);
+
+ if (isTypeChanged)
+ net_nfc_gdbus_secure_element_emit_se_type_changed(data->object,
+ data->se_type);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->object);
+
+ g_free(data);
+}
+
+static gboolean se_handle_set(
+ NetNfcGDbusSecureElement *object,
+ GDBusMethodInvocation *invocation,
+ gint arg_type,
+ GVariant *smack_privilege)
+{
+ SeDataSeType *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(SeDataSeType, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->object = g_object_ref(object);
+ data->invocation = g_object_ref(invocation);
+ data->se_type = arg_type;
+
+ result = net_nfc_server_controller_async_queue_push(
+ se_set_data_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Se.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->object);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+gboolean net_nfc_server_se_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (se_skeleton)
+ g_object_unref(se_skeleton);
+
+ /* initialize UICC */
+ _se_uicc_init();
+
+ se_skeleton = net_nfc_gdbus_secure_element_skeleton_new();
+
+ g_signal_connect(se_skeleton,
+ "handle-set",
+ G_CALLBACK(se_handle_set),
+ NULL);
+ g_signal_connect(se_skeleton,
+ "handle-open-secure-element",
+ G_CALLBACK(se_handle_open_secure_element),
+ NULL);
+
+ g_signal_connect(se_skeleton,
+ "handle-close-secure-element",
+ G_CALLBACK(se_handle_close_secure_element),
+ NULL);
+
+ g_signal_connect(se_skeleton,
+ "handle-get-atr",
+ G_CALLBACK(se_handle_get_atr),
+ NULL);
+
+ g_signal_connect(se_skeleton,
+ "handle-send-apdu",
+ G_CALLBACK(se_handle_send_apdu),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(se_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/SecureElement",
+ &error);
+ if (result == FALSE)
+ {
+ DEBUG_ERR_MSG("can not skeleton_export %s", error->message);
+
+ g_error_free(error);
+
+ net_nfc_server_se_deinit();
+ }
+
+ return result;
+}
+
+void net_nfc_server_se_deinit(void)
+{
+ if (se_skeleton)
+ {
+ g_object_unref(se_skeleton);
+ se_skeleton = NULL;
+
+ /* de-initialize UICC */
+ _se_uicc_deinit();
+ }
+}
+
+static void se_detected_thread_func(gpointer user_data)
+{
+ net_nfc_target_handle_s *handle;
+ uint32_t devType;
+ GVariant *data;
+ net_nfc_error_e result;
+
+ g_assert(user_data != NULL);
+
+ if (se_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("se skeleton is not initialized");
+
+ g_variant_unref((GVariant *)user_data);
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "uu@a(y)",
+ (guint *)&handle,
+ &devType,
+ &data);
+
+ net_nfc_server_se_set_current_ese_handle(handle);
+
+ DEBUG_SERVER_MSG("trying to connect to ESE = [0x%p]", handle);
+
+ if (!net_nfc_controller_connect(handle, &result))
+ {
+ DEBUG_SERVER_MSG("connect failed = [%d]", result);
+ }
+
+ net_nfc_gdbus_secure_element_emit_ese_detected(
+ se_skeleton,
+ GPOINTER_TO_UINT(handle),
+ devType,
+ data);
+
+ g_variant_unref((GVariant *)user_data);
+}
+
+static void se_transcation_thread_func(gpointer user_data)
+{
+ ServerSeData *detail = (ServerSeData *)user_data;
+
+ g_assert(user_data != NULL);
+
+ if (detail->event == NET_NFC_MESSAGE_SE_START_TRANSACTION)
+ {
+ DEBUG_SERVER_MSG("launch se app");
+
+ net_nfc_app_util_launch_se_transaction_app(
+ detail->aid.buffer,
+ detail->aid.length,
+ detail->param.buffer,
+ detail->param.length);
+
+ DEBUG_SERVER_MSG("launch se app end");
+ }
+
+ net_nfc_util_free_data(&detail->param);
+ net_nfc_util_free_data(&detail->aid);
+
+ g_free(detail);
+}
+
+void net_nfc_server_se_detected(void *info)
+{
+ net_nfc_request_target_detected_t *se_target =
+ (net_nfc_request_target_detected_t *)info;
+ GVariant *parameter;
+ GVariant *data;
+
+ data = net_nfc_util_gdbus_buffer_to_variant(
+ se_target->target_info_values.buffer,
+ se_target->target_info_values.length);
+
+ parameter = g_variant_new("uu@a(y)",
+ GPOINTER_TO_UINT(se_target->handle),
+ se_target->devType,
+ data);
+ if (parameter != NULL) {
+ if (net_nfc_server_controller_async_queue_push(
+ se_detected_thread_func,
+ parameter) == FALSE) {
+ DEBUG_ERR_MSG("can not push to controller thread");
+
+ g_variant_unref(parameter);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_variant_new failed");
+ }
+
+ /* FIXME : should be removed when plugins would be fixed*/
+ _net_nfc_util_free_mem(info);
+}
+
+void net_nfc_server_se_transaction_received(void *info)
+{
+ net_nfc_request_se_event_t *se_event =
+ (net_nfc_request_se_event_t *)info;
+ ServerSeData *detail;
+
+ detail = g_new0(ServerSeData, 1);
+ if (detail != NULL) {
+ detail->event = se_event->request_type;
+
+ if (se_event->aid.buffer != NULL && se_event->aid.length > 0) {
+ if (net_nfc_util_alloc_data(&detail->aid,
+ se_event->aid.length) == true) {
+ memcpy(detail->aid.buffer, se_event->aid.buffer,
+ se_event->aid.length);
+ }
+ }
+
+ if (se_event->param.buffer != NULL &&
+ se_event->param.length > 0) {
+ if (net_nfc_util_alloc_data(&detail->param,
+ se_event->param.length) == true) {
+ memcpy(detail->param.buffer,
+ se_event->param.buffer,
+ se_event->param.length);
+ }
+ }
+
+ if (net_nfc_server_controller_async_queue_push(
+ se_transcation_thread_func, detail) == FALSE) {
+ DEBUG_ERR_MSG("can not push to controller thread");
+
+ net_nfc_util_free_data(&detail->param);
+ net_nfc_util_free_data(&detail->aid);
+
+ g_free(detail);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_new0 failed");
+ }
+
+ /* FIXME : should be removed when plugins would be fixed*/
+ net_nfc_util_free_data(&se_event->param);
+ net_nfc_util_free_data(&se_event->aid);
+
+ _net_nfc_util_free_mem(info);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_defines.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_llcp.h"
+#include "net_nfc_server_snep.h"
+#include "net_nfc_server_process_snep.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_server_context_internal.h"
+
+/* declaration */
+static gboolean _handle_start_server(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege);
+
+static gboolean _handle_start_client(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege);
+
+static gboolean _handle_client_send_request(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_snep_handle,
+ guint arg_type,
+ GVariant *arg_ndef_msg,
+ GVariant *arg_privilege);
+
+static gboolean _handle_stop_snep(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_snep_handle,
+ GVariant *arg_privilege);
+
+static void snep_server_start_thread_func(gpointer user_data);
+
+static void snep_client_start_thread_func(gpointer user_data);
+
+static void snep_client_send_request_thread_func(gpointer user_data);
+
+static void snep_stop_service_thread_func(gpointer user_data);
+
+/* definition */
+static NetNfcGDbusSnep *snep_skeleton = NULL;
+
+static void _emit_snep_event_signal(GVariant *parameter,
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data)
+{
+ GDBusConnection *connection;
+ char *client_id;
+ void *user_data;
+ GVariant *arg_data;
+ GError *error = NULL;
+
+ g_variant_get(parameter, "(usu)",
+ (guint *)&connection,
+ &client_id,
+ (guint *)&user_data);
+
+ arg_data = net_nfc_util_gdbus_data_to_variant(data);
+
+ if (g_dbus_connection_emit_signal(
+ connection,
+ client_id,
+ "/org/tizen/NetNfcService/Snep",
+ "org.tizen.NetNfcService.Snep",
+ "SnepEvent",
+ g_variant_new("(uui@a(y)u)",
+ GPOINTER_TO_UINT(handle),
+ type,
+ (gint)result,
+ arg_data,
+ GPOINTER_TO_UINT(user_data)),
+ &error) == false) {
+ if (error != NULL && error->message != NULL) {
+ DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed : %s", error->message);
+ } else {
+ DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed");
+ }
+ }
+
+ g_free(client_id);
+}
+
+static net_nfc_error_e _snep_server_cb(net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ GVariant *parameter = (GVariant *)user_param;
+
+ data_s *temp = data;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ switch (type)
+ {
+ case SNEP_REQ_GET :
+ {
+ uint32_t max_len = 0;
+
+ net_nfc_server_snep_parse_get_request(data, &max_len,
+ temp);
+ }
+ break;
+
+ case SNEP_REQ_PUT :
+ break;
+
+ default :
+ DEBUG_ERR_MSG("error [%d]", result);
+ break;
+ }
+
+ if (result < NET_NFC_OK) {
+ type = NET_NFC_LLCP_STOP;
+ }
+
+ _emit_snep_event_signal(parameter, handle,
+ result, type, data);
+
+ if (type == NET_NFC_LLCP_STOP) {
+ g_object_unref(parameter);
+ }
+
+ return result;
+}
+
+static void snep_server_start_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s *arg_handle;
+ guint arg_sap;
+ gchar *arg_san;
+ void *arg_user_data;
+ net_nfc_error_e result;
+
+ GVariant *parameter;
+ GDBusConnection *connection;
+
+ if (user_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot get SNEP client data");
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uuuusu)",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&arg_handle,
+ &arg_sap,
+ &arg_san,
+ (guint *)&arg_user_data);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ connection = g_dbus_method_invocation_get_connection(invocation);
+
+ parameter = g_variant_new("(usu)",
+ GPOINTER_TO_UINT(g_object_ref(connection)),
+ g_dbus_method_invocation_get_sender(invocation),
+ GPOINTER_TO_UINT(arg_user_data));
+ if (parameter != NULL) {
+ result = net_nfc_server_snep_server(arg_handle,
+ arg_san,
+ arg_sap,
+ _snep_server_cb,
+ parameter);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_server_snep_server failed, [%d]",
+ result);
+ g_object_unref(connection);
+
+ g_variant_unref(parameter);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_object_unref(connection);
+
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ net_nfc_gdbus_snep_complete_server_start(object, invocation, result);
+
+ g_free(arg_san);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_start_server(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuuusu)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_handle,
+ arg_sap,
+ arg_san,
+ arg_user_data);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_server_start_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static net_nfc_error_e _snep_start_client_cb(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ uint32_t type,
+ data_s *data,
+ void *user_param)
+{
+ GVariant *parameter = (GVariant *)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ _emit_snep_event_signal(parameter, handle, result, type, data);
+
+ if (type == NET_NFC_LLCP_STOP) {
+ g_variant_unref(parameter);
+ }
+
+ return result;
+}
+
+static void snep_client_start_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s *arg_handle;
+ guint arg_sap;
+ gchar *arg_san;
+ void *arg_user_data;
+ net_nfc_error_e result;
+
+ GVariant *parameter;
+ GDBusConnection *connection;
+
+ if (user_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot get SNEP client data");
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uuuusu)",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&arg_handle,
+ &arg_sap,
+ &arg_san,
+ (guint *)&arg_user_data);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ connection = g_dbus_method_invocation_get_connection(invocation);
+
+ parameter = g_variant_new("(usu)",
+ GPOINTER_TO_UINT(g_object_ref(connection)),
+ g_dbus_method_invocation_get_sender(invocation),
+ GPOINTER_TO_UINT(arg_user_data));
+ if (parameter != NULL) {
+ result = net_nfc_server_snep_client(arg_handle,
+ arg_san,
+ arg_sap,
+ _snep_start_client_cb,
+ parameter);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_server_snep_client failed, [%d]",
+ result);
+ g_object_unref(connection);
+
+ g_variant_unref(parameter);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_object_unref(connection);
+
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ net_nfc_gdbus_snep_complete_client_start(object, invocation, result);
+
+ g_free(arg_san);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_start_client(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuuusu)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_handle,
+ arg_sap,
+ arg_san,
+ arg_user_data);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_client_start_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_object_unref(g_variant_unref);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static net_nfc_error_e _snep_client_request_cb(
+ net_nfc_snep_handle_h handle,
+ net_nfc_error_e result,
+ net_nfc_snep_type_t type,
+ data_s *data,
+ void *user_param)
+{
+ GVariant *parameter = (GVariant *)user_param;
+
+ DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
+ type, result, data, user_param);
+
+ if (parameter != NULL) {
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_snep_handle_h arg_snep_handle;
+ net_nfc_snep_type_t arg_type;
+ GVariant *arg_ndef_msg;
+ GVariant *arg_data = NULL;
+
+ g_variant_get(parameter,
+ "(uuuu@a(y))",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&arg_snep_handle,
+ (guint *)&arg_type,
+ &arg_ndef_msg);
+
+ if (data != NULL && data->buffer != NULL && data->length > 0) {
+ arg_data = net_nfc_util_gdbus_data_to_variant(data);
+ } else {
+ arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ }
+
+ net_nfc_gdbus_snep_complete_client_request(object,
+ invocation,
+ result,
+ type,
+ arg_data);
+
+ g_variant_unref(arg_ndef_msg);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+
+ result = NET_NFC_OK;
+ } else {
+ result = NET_NFC_NULL_PARAMETER;
+ }
+
+ return result;
+}
+
+static void snep_client_send_request_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_snep_handle_h arg_snep_handle;
+ net_nfc_snep_type_t arg_type;
+ GVariant *arg_ndef_msg;
+ data_s data = { NULL, };
+ net_nfc_error_e result;
+
+ if (user_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot get SNEP client data");
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uuuu@a(y))",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&arg_snep_handle,
+ (guint *)&arg_type,
+ &arg_ndef_msg);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_ndef_msg, &data);
+
+ result = net_nfc_server_snep_client_request(arg_snep_handle,
+ arg_type,
+ &data,
+ _snep_client_request_cb,
+ user_data);
+ if (result != NET_NFC_OK)
+ {
+ GVariant *resp;
+
+ DEBUG_ERR_MSG("net_nfc_server_snep_client_request "
+ "failed, [%d]",result);
+
+ resp = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+
+ net_nfc_gdbus_snep_complete_client_request(object,
+ invocation, result, NET_NFC_LLCP_STOP, resp);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(user_data);
+ }
+
+ net_nfc_util_free_data(&data);
+
+ g_variant_unref(arg_ndef_msg);
+}
+
+static gboolean _handle_client_send_request(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_snep_handle,
+ guint arg_type,
+ GVariant *arg_ndef_msg,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuuu@a(y))",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_snep_handle,
+ arg_type,
+ arg_ndef_msg);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_client_send_request_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static void snep_stop_service_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ net_nfc_target_handle_s *handle;
+ net_nfc_snep_handle_h snep_handle;
+
+ if (user_data == NULL)
+ {
+ DEBUG_ERR_MSG("cannot get SNEP client data");
+
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uuuu)",
+ (guint *)&object,
+ (guint *)&invocation,
+ (guint *)&handle,
+ (guint *)&snep_handle);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ /* TODO :
+ g_dbus_method_invocation_return_dbus_error(
+ invocation,
+ "org.tizen.NetNfcService.Snep.DataError",
+ "Cannot stop SNEP service");
+ */
+
+ net_nfc_gdbus_snep_complete_stop_snep(object,
+ invocation,
+ NET_NFC_OK);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_stop_snep(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_handle,
+ guint arg_snep_handle,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuuu)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_handle,
+ arg_snep_handle);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_stop_service_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static void _snep_activate_cb(int event, net_nfc_target_handle_s *handle,
+ uint32_t sap, const char *san, void *user_param)
+{
+ GVariant *parameter = (GVariant *)user_param;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ DEBUG_SERVER_MSG("event [%d], handle [%p], sap [%d], san [%s]",
+ event, handle, sap, san);
+
+ if (event == NET_NFC_LLCP_START) {
+ GDBusConnection *connection;
+ GVariant *param = NULL;
+ char *client_id;
+ void *user_data;
+
+ /* start server */
+ g_variant_get(parameter, "(usu)",
+ (guint *)&connection,
+ &client_id,
+ (guint *)&user_data);
+
+ param = g_variant_new("(usu)",
+ GPOINTER_TO_UINT(g_object_ref(connection)),
+ client_id,
+ GPOINTER_TO_UINT(user_data));
+
+ g_free(client_id);
+
+ result = net_nfc_server_snep_server(handle, (char *)san, sap,
+ _snep_server_cb, param);
+ if (result == NET_NFC_OK) {
+ _emit_snep_event_signal(parameter, handle,
+ result, event, NULL);
+ } else {
+ DEBUG_ERR_MSG("net_nfc_server_snep_server failed, [%d]",
+ result);
+
+ g_variant_unref(param);
+ }
+ } else {
+ _emit_snep_event_signal(parameter, handle,
+ result, NET_NFC_LLCP_UNREGISTERED, NULL);
+
+ /* unregister server */
+ g_variant_unref(parameter);
+ }
+}
+
+static void snep_register_server_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ guint arg_sap;
+ gchar *arg_san;
+ guint arg_user_data;
+
+ net_nfc_error_e result;
+ GVariant *parameter = NULL;
+ GDBusConnection *connection;
+
+ g_assert(user_data != NULL);
+
+ g_variant_get((GVariant *)user_data,
+ "(uuusu)",
+ (guint *)&object,
+ (guint *)&invocation,
+ &arg_sap,
+ &arg_san,
+ &arg_user_data);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ connection = g_dbus_method_invocation_get_connection(invocation);
+
+ parameter = g_variant_new("(usu)",
+ GPOINTER_TO_UINT(g_object_ref(connection)),
+ g_dbus_method_invocation_get_sender(invocation),
+ arg_user_data);
+ if (parameter != NULL) {
+ /* register default snep server */
+ result = net_nfc_server_llcp_register_service(
+ g_dbus_method_invocation_get_sender(invocation),
+ arg_sap,
+ arg_san,
+ _snep_activate_cb,
+ parameter);
+ if (result != NET_NFC_OK) {
+ DEBUG_ERR_MSG("net_nfc_service_llcp_register_service failed, [%d]", result);
+ g_object_unref(connection);
+ g_variant_unref(parameter);
+ }
+ } else {
+ result = NET_NFC_ALLOC_FAIL;
+ g_object_unref(connection);
+ }
+
+ net_nfc_gdbus_snep_complete_server_register(object,
+ invocation,
+ result);
+
+ g_free(arg_san);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_register_server(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_sap,
+ const gchar *arg_san,
+ guint arg_user_data,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuusu)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_sap,
+ arg_san,
+ arg_user_data);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_register_server_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+static void snep_unregister_server_thread_func(gpointer user_data)
+{
+ NetNfcGDbusSnep *object;
+ GDBusMethodInvocation *invocation;
+ guint arg_sap;
+ gchar *arg_san;
+
+ net_nfc_error_e result;
+
+ g_assert(user_data != NULL);
+
+ g_variant_get((GVariant *)user_data,
+ "(uuus)",
+ (guint *)&object,
+ (guint *)&invocation,
+ &arg_sap,
+ &arg_san);
+
+ g_assert(object != NULL);
+ g_assert(invocation != NULL);
+
+ result = net_nfc_server_llcp_unregister_service(
+ g_dbus_method_invocation_get_sender(invocation),
+ arg_sap,
+ arg_san);
+
+ net_nfc_gdbus_snep_complete_server_unregister(object,
+ invocation,
+ result);
+
+ g_free(arg_san);
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(user_data);
+}
+
+static gboolean _handle_unregister_server(
+ NetNfcGDbusSnep *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_sap,
+ const gchar *arg_san,
+ GVariant *arg_privilege)
+{
+ GVariant *parameter;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ arg_privilege,
+ "nfc-manager::p2p",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ parameter = g_variant_new("(uuus)",
+ GPOINTER_TO_UINT(g_object_ref(object)),
+ GPOINTER_TO_UINT(g_object_ref(invocation)),
+ arg_sap,
+ arg_san);
+
+ if (parameter != NULL)
+ {
+ if ((result = net_nfc_server_controller_async_queue_push(
+ snep_unregister_server_thread_func, parameter)) == FALSE)
+ {
+ DEBUG_ERR_MSG("net_nfc_server_controller_async_queue_push failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(invocation);
+ g_object_unref(object);
+
+ g_variant_unref(parameter);
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("g_variant_new failed");
+
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Snep.MemoryError",
+ "Out of memory");
+
+ result = FALSE;
+ }
+
+ return result;
+}
+
+gboolean net_nfc_server_snep_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (snep_skeleton)
+ g_object_unref(snep_skeleton);
+
+ snep_skeleton = net_nfc_gdbus_snep_skeleton_new();
+
+ g_signal_connect(snep_skeleton,
+ "handle-server-register",
+ G_CALLBACK(_handle_register_server),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-server-unregister",
+ G_CALLBACK(_handle_unregister_server),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-server-start",
+ G_CALLBACK(_handle_start_server),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-client-start",
+ G_CALLBACK(_handle_start_client),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-client-request",
+ G_CALLBACK(_handle_client_send_request),
+ NULL);
+
+ g_signal_connect(snep_skeleton,
+ "handle-stop-snep",
+ G_CALLBACK(_handle_stop_snep),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(snep_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Snep",
+ &error);
+ if (result == FALSE)
+ {
+ g_error_free(error);
+
+ net_nfc_server_snep_deinit();
+ }
+
+ return result;
+}
+
+void net_nfc_server_snep_deinit(void)
+{
+ if (snep_skeleton)
+ {
+ g_object_unref(snep_skeleton);
+ snep_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "net_nfc_gdbus.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context_internal.h"
+#include "net_nfc_server_system_handler.h"
+
+
+static NetNfcGDbusPopup *popup_skeleton = NULL;
+
+static gboolean popup_handle_set(NetNfcGDbusPopup *popup_manager,
+ GDBusMethodInvocation *invocation,
+ gboolean state,
+ gint focus_state,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean popup_handle_set(NetNfcGDbusPopup *popup_manager,
+ GDBusMethodInvocation *invocation,
+ gboolean state,
+ gint focus_state,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ net_nfc_server_gdbus_set_launch_state(
+ g_dbus_method_invocation_get_sender(invocation),
+ state, focus_state);
+
+ net_nfc_gdbus_popup_complete_set(popup_manager, invocation);
+
+ return TRUE;
+}
+
+static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ gboolean state;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ state = net_nfc_server_gdbus_get_launch_state(
+ g_dbus_method_invocation_get_sender(invocation));
+
+ net_nfc_gdbus_popup_complete_get(popup_manager, invocation, state);
+
+ return TRUE;
+}
+
+gboolean net_nfc_server_system_handler_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (popup_skeleton)
+ g_object_unref(popup_skeleton);
+
+ popup_skeleton = net_nfc_gdbus_popup_skeleton_new();
+ if (popup_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("Failed to allocate popup skeleton");
+
+ return FALSE;
+ }
+
+ g_signal_connect(popup_skeleton,
+ "handle-set",
+ G_CALLBACK(popup_handle_set),
+ NULL);
+
+ g_signal_connect(popup_skeleton,
+ "handle-get",
+ G_CALLBACK(popup_handle_get),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(popup_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Popup",
+ &error);
+ if (result == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
+
+ g_error_free(error);
+ g_object_unref(popup_skeleton);
+ popup_skeleton = NULL;
+ }
+
+ return result;
+}
+
+void net_nfc_server_system_handler_deinit(void)
+{
+ if(popup_skeleton)
+ {
+ g_object_unref(popup_skeleton);
+ popup_skeleton = NULL;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_app_util_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context_internal.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_p2p.h"
+
+
+typedef struct _CurrentTagInfoData CurrentTagInfoData;
+
+struct _CurrentTagInfoData
+{
+ NetNfcGDbusTag *tag;
+ GDBusMethodInvocation *invocation;
+};
+
+typedef struct _WatchDogData WatchDogData;
+
+struct _WatchDogData
+{
+ net_nfc_target_type_e dev_type;
+ net_nfc_target_handle_s *handle;
+};
+
+
+static gboolean tag_is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle,
+ int dev_type);
+
+static gboolean tag_read_ndef_message(net_nfc_target_handle_s *handle,
+ int dev_type,
+ data_s **read_ndef);
+
+static void tag_watchdog_thread_func(gpointer user_data);
+
+static void tag_get_current_tag_info_thread_func(gpointer user_data);
+
+static void tag_slave_target_detected_thread_func(gpointer user_data);
+
+
+/* methods */
+static gboolean tag_handle_is_tag_connected(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean tag_handle_get_current_tag_info(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean tag_handle_get_current_target_handle(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static NetNfcGDbusTag *tag_skeleton = NULL;
+
+static net_nfc_current_target_info_s *current_target_info = NULL;
+
+static gboolean tag_is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle,
+ int dev_type)
+{
+ uint8_t cmd[] = { 0x90, 0x60, 0x00, 0x00, 0x00 };
+
+ net_nfc_transceive_info_s info;
+ data_s *response = NULL;
+ net_nfc_error_e error = NET_NFC_OK;
+ gboolean result = false;
+
+ info.dev_type = dev_type;
+ info.trans_data.buffer = cmd;
+ info.trans_data.length = sizeof(cmd);
+
+ if (net_nfc_controller_transceive(handle,
+ &info,
+ &response,
+ &error) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_transceive is failed");
+
+ return result;
+ }
+
+ if (response != NULL)
+ {
+ if (response->length == 9 &&
+ response->buffer[7] == (uint8_t)0x91 &&
+ response->buffer[8] == (uint8_t)0xAF)
+ {
+ result = TRUE;
+ }
+
+ net_nfc_util_free_data(response);
+ g_free(response);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("response is NULL");
+ }
+
+ return result;
+}
+
+static gboolean tag_read_ndef_message(net_nfc_target_handle_s *handle,
+ int dev_type,
+ data_s **read_ndef)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_s *temp = NULL;
+
+ if (handle == NULL)
+ return FALSE;
+
+ if (read_ndef == NULL)
+ return FALSE;
+
+ *read_ndef = NULL;
+
+ if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC)
+ {
+ if (tag_is_isp_dep_ndef_formatable(handle, dev_type) == FALSE)
+ {
+ DEBUG_ERR_MSG(
+ "DESFIRE : ISO-DEP ndef not formatable");
+ return FALSE;
+ }
+
+ DEBUG_SERVER_MSG("DESFIRE : ISO-DEP ndef formatable");
+
+ if (net_nfc_controller_connect(handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, & retry polling!!",
+ "net_nfc_controller_connect");
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_RESUME,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ net_nfc_controller_exception_handler();
+ }
+ return FALSE;
+ }
+ }
+
+ if (net_nfc_controller_read_ndef(handle, &temp, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed",
+ "net_nfc_controller_read_ndef");
+ return FALSE;
+ }
+
+ DEBUG_SERVER_MSG("%s success",
+ "net_nfc_controller_read_ndef");
+
+ if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC)
+ {
+ if (net_nfc_controller_connect(handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("%s failed, & retry polling!!",
+ "net_nfc_controller_connect");
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_RESUME,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ net_nfc_controller_exception_handler();
+ }
+
+ if (temp)
+ {
+ g_free(temp->buffer);
+ g_free(temp);
+ }
+
+ return FALSE;
+ }
+ }
+
+ *read_ndef = temp;
+
+ return TRUE;
+}
+
+static void tag_watchdog_thread_func(gpointer user_data)
+{
+ WatchDogData *watch_dog = (WatchDogData *)user_data;
+ net_nfc_target_handle_s *handle;
+ net_nfc_error_e result = NET_NFC_OK;
+ bool is_present_target = false;
+
+ if (watch_dog == NULL)
+ {
+ DEBUG_ERR_MSG("can not get WatchDogData");
+ return;
+ }
+
+ if (watch_dog->handle == NULL)
+ {
+ DEBUG_ERR_MSG("can not get WatchDogData->handle");
+ return;
+ }
+
+
+ /* IMPORTANT, TEMPORARY : switching context to another thread
+ for give CPU time */
+ g_usleep(10000);
+
+ handle = watch_dog->handle;
+ if (handle->connection_type == NET_NFC_P2P_CONNECTION_TARGET ||
+ handle->connection_type == NET_NFC_TAG_CONNECTION)
+ {
+ is_present_target = net_nfc_controller_check_target_presence(
+ handle, &result);
+ }
+
+ if (is_present_target == true)
+ {
+ if(net_nfc_server_controller_async_queue_push(
+ tag_watchdog_thread_func,
+ watch_dog) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not create watch dog");
+ g_free(watch_dog);
+ }
+ return;
+ }
+
+ if (result != NET_NFC_NOT_INITIALIZED &&
+ result != NET_NFC_INVALID_HANDLE)
+ {
+ if(net_nfc_controller_disconnect(handle, &result) == false)
+ {
+ DEBUG_SERVER_MSG("try to disconnect result = [%d]",
+ result);
+ net_nfc_controller_exception_handler();
+ }
+ }
+
+ net_nfc_server_set_state(NET_NFC_SERVER_IDLE);
+
+ net_nfc_gdbus_tag_emit_tag_detached(tag_skeleton,
+ GPOINTER_TO_UINT(handle),
+ watch_dog->dev_type);
+
+ g_free(watch_dog);
+}
+
+static void tag_get_current_tag_info_thread_func(gpointer user_data)
+{
+ CurrentTagInfoData *info_data =
+ (CurrentTagInfoData *)user_data;
+
+ /* FIXME : net_nfc_current_target_info_s should be removed */
+ net_nfc_current_target_info_s *target_info;
+ net_nfc_error_e result;
+ net_nfc_target_handle_s *handle = NULL;
+ net_nfc_target_type_e dev_type = NET_NFC_UNKNOWN_TARGET;
+ gboolean is_ndef_supported = FALSE;
+ guint8 ndef_card_state = 0;
+ guint32 max_data_size = 0;
+ guint32 actual_data_size = 0;
+ gint number_of_keys = 0;
+ data_s target_info_values = { NULL, 0 };
+ data_s *raw_data = NULL;
+
+ g_assert(info_data != NULL);
+ g_assert(info_data->tag != NULL);
+ g_assert(info_data->invocation != NULL);
+
+ target_info = net_nfc_server_get_target_info();
+ if (target_info != NULL &&
+ target_info->devType != NET_NFC_NFCIP1_TARGET &&
+ target_info->devType != NET_NFC_NFCIP1_INITIATOR)
+ {
+ handle = target_info->handle;
+ number_of_keys = target_info->number_of_keys;
+
+ target_info_values.buffer = target_info->target_info_values.buffer;
+ target_info_values.length = target_info->target_info_values.length;
+
+ dev_type = target_info->devType ;
+
+ if (net_nfc_controller_check_ndef(target_info->handle,
+ &ndef_card_state,
+ (int *)&max_data_size,
+ (int *)&actual_data_size,
+ &result) == true)
+ {
+ is_ndef_supported = TRUE;
+ }
+
+ if (is_ndef_supported)
+ {
+ if (net_nfc_controller_read_ndef(target_info->handle,
+ &raw_data, &result) == true)
+ {
+ DEBUG_SERVER_MSG("%s is success",
+ "net_nfc_controller_read_ndef");
+ }
+ }
+ }
+
+ net_nfc_gdbus_tag_complete_get_current_tag_info(info_data->tag,
+ info_data->invocation,
+ (dev_type != NET_NFC_UNKNOWN_TARGET),
+ GPOINTER_TO_UINT(handle),
+ dev_type,
+ is_ndef_supported,
+ ndef_card_state,
+ max_data_size,
+ actual_data_size,
+ number_of_keys,
+ net_nfc_util_gdbus_data_to_variant(&target_info_values),
+ net_nfc_util_gdbus_data_to_variant(raw_data));
+
+ if (raw_data != NULL) {
+ net_nfc_util_free_data(raw_data);
+ g_free(raw_data);
+ }
+
+ g_object_unref(info_data->invocation);
+ g_object_unref(info_data->tag);
+
+ g_free(info_data);
+}
+
+static void tag_slave_target_detected_thread_func(gpointer user_data)
+{
+ net_nfc_current_target_info_s *target;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ guint32 max_data_size = 0;
+ guint32 actual_data_size = 0;
+ guint8 ndef_card_state = 0;
+ gboolean is_ndef_supported = FALSE;
+
+ GVariant *target_info_values = NULL;
+ GVariant *raw_data = NULL;
+
+ WatchDogData *watch_dog = NULL;
+
+ target = net_nfc_server_get_target_info();
+
+ g_assert(target != NULL); /* raise exception!!! what;s wrong?? */
+
+ if (tag_skeleton == NULL)
+ {
+ DEBUG_ERR_MSG("tag skeleton is not initialized");
+
+ return;
+ }
+
+ if (net_nfc_controller_connect(target->handle, &result) == false)
+ {
+ DEBUG_ERR_MSG("connect failed & Retry Polling!!");
+
+ if (net_nfc_controller_configure_discovery(
+ NET_NFC_DISCOVERY_MODE_RESUME,
+ NET_NFC_ALL_ENABLE,
+ &result) == false)
+ {
+ net_nfc_controller_exception_handler();
+ }
+
+ return;
+ }
+
+ net_nfc_server_set_state(NET_NFC_TAG_CONNECTED);
+
+ DEBUG_SERVER_MSG("tag is connected");
+
+ target_info_values = net_nfc_util_gdbus_buffer_to_variant(
+ target->target_info_values.buffer,
+ target->target_info_values.length);
+
+ if (net_nfc_controller_check_ndef(target->handle,
+ &ndef_card_state,
+ (int *)&max_data_size,
+ (int *)&actual_data_size,
+ &result) == true)
+ {
+ is_ndef_supported = TRUE;
+ }
+
+ if (is_ndef_supported)
+ {
+ data_s *recv_data = NULL;
+
+ DEBUG_SERVER_MSG("support NDEF");
+
+ if (tag_read_ndef_message(target->handle,
+ target->devType,
+ &recv_data) == TRUE)
+ {
+ net_nfc_app_util_process_ndef(recv_data);
+ raw_data = net_nfc_util_gdbus_data_to_variant(recv_data);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed");
+ raw_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
+ }
+ }
+ else
+ {
+ /* raw-data of empty ndef msseages */
+ uint8_t empty[] = { 0xd0, 0x00, 0x00 };
+ data_s empty_data = { empty, sizeof(empty) };
+
+ DEBUG_SERVER_MSG("not support NDEF");
+
+ net_nfc_app_util_process_ndef(&empty_data);
+ raw_data = net_nfc_util_gdbus_data_to_variant(&empty_data);
+ }
+
+ /* send TagDiscoverd signal */
+ net_nfc_gdbus_tag_emit_tag_discovered(tag_skeleton,
+ GPOINTER_TO_UINT(target->handle),
+ target->devType,
+ is_ndef_supported,
+ ndef_card_state,
+ max_data_size,
+ actual_data_size,
+ target->number_of_keys,
+ target_info_values,
+ raw_data);
+
+ /* turn on watch dog */
+ DEBUG_SERVER_MSG("turn on watch dog");
+
+ watch_dog = g_new0(WatchDogData, 1);
+ if(watch_dog == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ return;
+ }
+
+ watch_dog->dev_type = target->devType;
+ watch_dog->handle = target->handle;
+
+ if (net_nfc_server_controller_async_queue_push(
+ tag_watchdog_thread_func,
+ watch_dog) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not create watch dog");
+ g_free(watch_dog);
+ return;
+ }
+}
+
+
+static gboolean tag_handle_is_tag_connected(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ /* FIXME : net_nfc_current_target_info_s should be removed */
+ net_nfc_current_target_info_s *target_info;
+ net_nfc_target_type_e dev_type = NET_NFC_UNKNOWN_TARGET;
+ gboolean is_connected = FALSE;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ target_info = net_nfc_server_get_target_info();
+ if (target_info != NULL)
+ {
+ dev_type = target_info->devType;
+ is_connected = TRUE;
+ }
+
+ net_nfc_gdbus_tag_complete_is_tag_connected(tag,
+ invocation,
+ is_connected,
+ (gint32)dev_type);
+
+ return TRUE;
+}
+
+static gboolean tag_handle_get_current_tag_info(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ CurrentTagInfoData *info_data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ info_data = g_new0(CurrentTagInfoData, 1);
+ if (info_data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ info_data->tag = g_object_ref(tag);
+ info_data->invocation = g_object_ref(invocation);
+
+ result = net_nfc_server_controller_async_queue_push(
+ tag_get_current_tag_info_thread_func,
+ info_data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(info_data->invocation);
+ g_object_unref(info_data->tag);
+
+ g_free(info_data);
+ }
+
+ return result;
+}
+
+static gboolean tag_handle_get_current_target_handle(NetNfcGDbusTag *tag,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ /* FIXME : net_nfc_current_target_info_s should be removed */
+ net_nfc_current_target_info_s *target_info;
+ net_nfc_target_handle_s *handle = NULL;
+ uint32_t devType = NET_NFC_UNKNOWN_TARGET;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::tag",
+ "r") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ target_info = net_nfc_server_get_target_info();
+ if (target_info != NULL)
+ {
+ handle = target_info->handle;
+ devType = target_info->devType;
+ }
+
+ net_nfc_gdbus_tag_complete_get_current_target_handle(tag,
+ invocation,
+ (handle != NULL),
+ GPOINTER_TO_UINT(handle),
+ devType);
+
+ return TRUE;
+}
+
+
+gboolean net_nfc_server_tag_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (tag_skeleton)
+ net_nfc_server_tag_deinit();
+
+ tag_skeleton = net_nfc_gdbus_tag_skeleton_new();
+
+ g_signal_connect(tag_skeleton,
+ "handle-is-tag-connected",
+ G_CALLBACK(tag_handle_is_tag_connected),
+ NULL);
+
+ g_signal_connect(tag_skeleton,
+ "handle-get-current-tag-info",
+ G_CALLBACK(tag_handle_get_current_tag_info),
+ NULL);
+
+ g_signal_connect(tag_skeleton,
+ "handle-get-current-target-handle",
+ G_CALLBACK(tag_handle_get_current_target_handle),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(tag_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Tag",
+ &error);
+ if (result == FALSE)
+ {
+ DEBUG_ERR_MSG("can not skeleton_export %s", error->message);
+
+ g_error_free(error);
+
+ net_nfc_server_tag_deinit();
+ }
+
+ return result;
+}
+
+void net_nfc_server_tag_deinit(void)
+{
+ if (tag_skeleton)
+ {
+ g_object_unref(tag_skeleton);
+ tag_skeleton = NULL;
+ }
+}
+
+void net_nfc_server_set_target_info(void *info)
+{
+ net_nfc_request_target_detected_t *target;
+
+ if (current_target_info)
+ g_free(current_target_info);
+
+ target = (net_nfc_request_target_detected_t *)info;
+
+ current_target_info = g_malloc0(
+ sizeof(net_nfc_current_target_info_s) +
+ target->target_info_values.length);
+
+ current_target_info->handle = target->handle;
+ current_target_info->devType = target->devType;
+
+ if (current_target_info->devType != NET_NFC_NFCIP1_INITIATOR &&
+ current_target_info->devType != NET_NFC_NFCIP1_TARGET)
+ {
+ current_target_info->number_of_keys = target->number_of_keys;
+ current_target_info->target_info_values.length =
+ target->target_info_values.length;
+
+ memcpy(¤t_target_info->target_info_values,
+ &target->target_info_values,
+ current_target_info->target_info_values.length);
+ }
+}
+
+net_nfc_current_target_info_s *net_nfc_server_get_target_info(void)
+{
+ return current_target_info;
+}
+
+gboolean net_nfc_server_target_connected(net_nfc_target_handle_s *handle)
+{
+ if (current_target_info == NULL)
+ return FALSE;
+
+ if (current_target_info->handle != handle)
+ return FALSE;
+
+ return TRUE;
+}
+
+void net_nfc_server_free_target_info(void)
+{
+ g_free(current_target_info);
+ current_target_info = NULL;
+}
+
+void net_nfc_server_tag_target_detected(void *info)
+{
+ if (net_nfc_server_controller_async_queue_push(
+ tag_slave_target_detected_thread_func,
+ NULL) == FALSE)
+ {
+ DEBUG_ERR_MSG("can not push to controller thread");
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_context_internal.h"
+#include "net_nfc_server_test.h"
+
+typedef struct _TestData TestData;
+
+struct _TestData
+{
+ NetNfcGDbusTest *test;
+ GDBusMethodInvocation *invocation;
+};
+
+typedef struct _TestPrbsData TestPrbsData;
+
+struct _TestPrbsData
+{
+ NetNfcGDbusTest *test;
+ GDBusMethodInvocation *invocation;
+ guint32 tech;
+ guint32 rate;
+};
+
+typedef struct _TestSetEeData TestSetEeData;
+
+struct _TestSetEeData
+{
+ NetNfcGDbusTest *test;
+ GDBusMethodInvocation *invocation;
+
+ guint32 mode;
+ guint32 reg_id;
+ data_s data;
+};
+
+static void test_handle_sim_test_thread_func(gpointer user_data);
+
+static void test_handle_prbs_test_thread_func(gpointer user_data);
+
+static void test_handle_get_firmware_version_thread_func(gpointer user_data);
+
+static void test_handle_set_ee_data_thread_func(gpointer user_data);
+
+
+static gboolean test_handle_sim_test(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean test_handle_prbs_test(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_tech,
+ guint32 arg_rate,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean test_handle_get_firmware_version(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean test_handle_set_ee_data(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ guint32 mode,
+ guint32 reg_id,
+ GVariant *variant,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+static NetNfcGDbusTest *test_skeleton = NULL;
+
+static void test_handle_sim_test_thread_func(gpointer user_data)
+{
+ TestData *data = (TestData *)user_data;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(data != NULL);
+ g_assert(data->test != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_controller_sim_test(&result);
+
+ net_nfc_gdbus_test_complete_sim_test(data->test,
+ data->invocation,
+ (gint)result);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+}
+
+static void test_handle_prbs_test_thread_func(gpointer user_data)
+{
+ TestPrbsData *data = (TestPrbsData *)user_data;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(data != NULL);
+ g_assert(data->test != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_controller_prbs_test(&result, data->tech, data->rate);
+
+ net_nfc_gdbus_test_complete_prbs_test(data->test,
+ data->invocation,
+ (gint)result);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+}
+
+static void test_handle_get_firmware_version_thread_func(gpointer user_data)
+{
+ TestData *data = (TestData *)user_data;
+ data_s *tmp_data = NULL;
+ net_nfc_error_e result = NET_NFC_OK;
+ gchar *version = NULL;
+
+ g_assert(data != NULL);
+ g_assert(data->test != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_controller_get_firmware_version(&tmp_data, &result);
+
+ if (tmp_data)
+ {
+ version = g_new0(gchar, tmp_data->length +1);
+ memcpy((void *)version, tmp_data->buffer, tmp_data->length);
+
+ g_free(tmp_data->buffer);
+ g_free(tmp_data);
+ }
+ else
+ {
+ version = g_strdup("");
+ }
+
+ net_nfc_gdbus_test_complete_get_firmware_version(data->test,
+ data->invocation,
+ (gint)result,
+ version);
+
+ g_free(version);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+}
+
+static void test_handle_set_ee_data_thread_func(gpointer user_data)
+{
+ TestSetEeData *data = (TestSetEeData *)user_data;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ g_assert(data != NULL);
+ g_assert(data->test != NULL);
+ g_assert(data->invocation != NULL);
+
+ net_nfc_controller_eedata_register_set(&result,
+ data->mode,
+ data->reg_id,
+ &data->data);
+
+ net_nfc_gdbus_test_complete_set_ee_data(data->test,
+ data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+}
+
+static gboolean test_handle_sim_test(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TestData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ DEBUG_SERVER_MSG("sim_test");
+
+ data = g_new0(TestData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->test = g_object_ref(test);
+ data->invocation = g_object_ref(invocation);
+
+ result = net_nfc_server_controller_async_queue_push(
+ test_handle_sim_test_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean test_handle_prbs_test(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_tech,
+ guint32 arg_rate,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TestPrbsData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return TRUE;
+ }
+
+ DEBUG_SERVER_MSG("prbs_test");
+
+ data = g_new0(TestPrbsData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->test = g_object_ref(test);
+ data->invocation = g_object_ref(invocation);
+ data->tech = arg_tech;
+ data->rate = arg_rate;
+
+ result = net_nfc_server_controller_async_queue_push(
+ test_handle_prbs_test_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean test_handle_get_firmware_version(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TestData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(TestData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->test = g_object_ref(test);
+ data->invocation = g_object_ref(invocation);
+
+ result = net_nfc_server_controller_async_queue_push(
+ test_handle_get_firmware_version_thread_func,
+ data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ g_object_unref(data->test);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static gboolean test_handle_set_ee_data(NetNfcGDbusTest *test,
+ GDBusMethodInvocation *invocation,
+ guint32 mode,
+ guint32 reg_id,
+ GVariant *variant,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TestSetEeData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(TestSetEeData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->test = g_object_ref(test);
+ data->invocation = g_object_ref(invocation);
+ data->mode = mode;
+ data->reg_id = reg_id;
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data->data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ test_handle_set_ee_data_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->test);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+gboolean net_nfc_server_test_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (test_skeleton)
+ g_object_unref(test_skeleton);
+
+ test_skeleton = net_nfc_gdbus_test_skeleton_new();
+
+ g_signal_connect(test_skeleton,
+ "handle-sim-test",
+ G_CALLBACK(test_handle_sim_test),
+ NULL);
+
+ g_signal_connect(test_skeleton,
+ "handle-prbs-test",
+ G_CALLBACK(test_handle_prbs_test),
+ NULL);
+
+ g_signal_connect(test_skeleton,
+ "handle-get-firmware-version",
+ G_CALLBACK(test_handle_get_firmware_version),
+ NULL);
+
+ g_signal_connect(test_skeleton,
+ "handle-set-ee-data",
+ G_CALLBACK(test_handle_set_ee_data),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(test_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Test",
+ &error);
+ if (result == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);
+ g_error_free(error);
+ g_object_unref(test_skeleton);
+
+ test_skeleton = NULL;
+ }
+
+ return result;
+}
+
+void net_nfc_server_test_deinit(void)
+{
+ if (test_skeleton)
+ {
+ g_object_unref(test_skeleton);
+ test_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
+#include "net_nfc_controller_internal.h"
+#include "net_nfc_gdbus.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_tag.h"
+#include "net_nfc_server_context_internal.h"
+#include "net_nfc_server_transceive.h"
+
+
+static NetNfcGDbusTransceive *transceive_skeleton = NULL;
+
+static void transceive_thread_func(gpointer user_data);
+
+static void transceive_data_thread_func(gpointer user_data);
+
+static gboolean transceive_handle(NetNfcGDbusTransceive *transceive,
+ GDBusMethodInvocation *invocation,
+ guint handle,
+ guint dev_type,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+static gboolean transceive_data_handle(NetNfcGDbusTransceive *transceive,
+ GDBusMethodInvocation *invocation,
+ guint handle,
+ guint dev_type,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data);
+
+
+typedef struct _TransceiveSendData TransceiveSendData;
+
+struct _TransceiveSendData
+{
+ NetNfcGDbusTransceive *transceive;
+ GDBusMethodInvocation *invocation;
+ guint transceive_handle;
+ net_nfc_transceive_info_s transceive_info;
+};
+
+static void transceive_data_thread_func(gpointer user_data)
+{
+ TransceiveSendData *transceive_data = (TransceiveSendData*)user_data;
+ net_nfc_target_handle_s *handle =
+ (net_nfc_target_handle_s *)transceive_data->transceive_handle;
+ net_nfc_error_e result;
+ data_s *data = NULL;
+ GVariant *resp_data = NULL;
+
+ /* use assert because it was checked in handle function */
+ g_assert(transceive_data != NULL);
+ g_assert(transceive_data->transceive != NULL);
+ g_assert(transceive_data->invocation != NULL);
+
+ if (net_nfc_server_target_connected(handle) == true)
+ {
+ DEBUG_SERVER_MSG("call transceive");
+
+ if (net_nfc_controller_transceive(handle,
+ &transceive_data->transceive_info,
+ &data,
+ &result) == true)
+ {
+ if (data != NULL)
+ {
+ DEBUG_SERVER_MSG("Transceive data received [%d]",
+ data->length);
+ }
+ }
+ }
+ else
+ {
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ DEBUG_SERVER_MSG("transceive result : %d", result);
+
+ resp_data = net_nfc_util_gdbus_data_to_variant(data);
+
+ net_nfc_gdbus_transceive_complete_transceive_data(
+ transceive_data->transceive,
+ transceive_data->invocation,
+ (gint)result,
+ resp_data);
+
+ if (data)
+ {
+ g_free(data->buffer);
+ g_free(data);
+ }
+
+ net_nfc_util_free_data(&transceive_data->transceive_info.trans_data);
+
+ g_object_unref(transceive_data->invocation);
+ g_object_unref(transceive_data->transceive);
+
+ g_free(transceive_data);
+}
+
+static gboolean transceive_data_handle(NetNfcGDbusTransceive *transceive,
+ GDBusMethodInvocation *invocation,
+ guint handle,
+ guint dev_type,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TransceiveSendData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(TransceiveSendData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->transceive = g_object_ref(transceive);
+ data->invocation = g_object_ref(invocation);
+ data->transceive_handle = handle;
+ data->transceive_info.dev_type = dev_type;
+ net_nfc_util_gdbus_variant_to_data_s(arg_data,
+ &data->transceive_info.trans_data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ transceive_data_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Transceive.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->transceive_info.trans_data);
+
+ g_object_unref(data->transceive);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+static void transceive_thread_func(gpointer user_data)
+{
+ TransceiveSendData *transceive_data = (TransceiveSendData *)user_data;
+ net_nfc_target_handle_s *handle =
+ (net_nfc_target_handle_s *)transceive_data->transceive_handle;
+ net_nfc_error_e result = NET_NFC_OK;
+ data_s *data = NULL;
+
+ /* use assert because it was checked in handle function */
+ g_assert(transceive_data != NULL);
+ g_assert(transceive_data->transceive != NULL);
+ g_assert(transceive_data->invocation != NULL);
+
+ if (net_nfc_server_target_connected(handle) == true)
+ {
+ DEBUG_MSG("call transceive");
+
+ if (net_nfc_controller_transceive(handle,
+ &transceive_data->transceive_info,
+ &data,
+ &result) == true)
+ {
+ if (data != NULL)
+ {
+ DEBUG_SERVER_MSG(
+ "Transceive data received [%d]",
+ data->length);
+
+ /* free resource because it doesn't need */
+ g_free(data->buffer);
+ g_free(data);
+ }
+ }
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("target is not connected");
+
+ result = NET_NFC_TARGET_IS_MOVED_AWAY;
+ }
+
+ DEBUG_SERVER_MSG("transceive result : %d", result);
+
+ net_nfc_gdbus_transceive_complete_transceive(
+ transceive_data->transceive,
+ transceive_data->invocation,
+ (gint)result);
+
+ net_nfc_util_free_data(&transceive_data->transceive_info.trans_data);
+
+ g_object_unref(transceive_data->invocation);
+ g_object_unref(transceive_data->transceive);
+
+ g_free(transceive_data);
+}
+
+static gboolean transceive_handle(NetNfcGDbusTransceive *transceive,
+ GDBusMethodInvocation *invocation,
+ guint handle,
+ guint dev_type,
+ GVariant *arg_data,
+ GVariant *smack_privilege,
+ gpointer user_data)
+{
+ TransceiveSendData *data;
+ gboolean result;
+
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
+
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager",
+ "rw") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
+
+ return FALSE;
+ }
+
+ data = g_new0(TransceiveSendData, 1);
+ if (data == NULL)
+ {
+ DEBUG_ERR_MSG("Memory allocation failed");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
+
+ return FALSE;
+ }
+
+ data->transceive = g_object_ref(transceive);
+ data->invocation = g_object_ref(invocation);
+ data->transceive_handle = handle;
+ data->transceive_info.dev_type = dev_type;
+ net_nfc_util_gdbus_variant_to_data_s(arg_data,
+ &data->transceive_info.trans_data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ transceive_thread_func, data);
+ if (result == FALSE)
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Transceive.ThreadError",
+ "can not push to controller thread");
+
+ net_nfc_util_free_data(&data->transceive_info.trans_data);
+
+ g_object_unref(data->transceive);
+ g_object_unref(data->invocation);
+
+ g_free(data);
+ }
+
+ return result;
+}
+
+
+gboolean net_nfc_server_transceive_init(GDBusConnection *connection)
+{
+ GError *error = NULL;
+ gboolean result;
+
+ if (transceive_skeleton)
+ g_object_unref(transceive_skeleton);
+
+ transceive_skeleton = net_nfc_gdbus_transceive_skeleton_new();
+
+ g_signal_connect(transceive_skeleton,
+ "handle-transceive-data",
+ G_CALLBACK(transceive_data_handle),
+ NULL);
+
+ g_signal_connect(transceive_skeleton,
+ "handle-transceive",
+ G_CALLBACK(transceive_handle),
+ NULL);
+
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(transceive_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Transceive",
+ &error);
+ if (result == FALSE)
+ {
+ g_error_free(error);
+ g_object_unref(transceive_skeleton);
+ transceive_skeleton = NULL;
+ }
+
+ return result;
+}
+
+void net_nfc_server_transceive_deinit(void)
+{
+ if (transceive_skeleton)
+ {
+ g_object_unref(transceive_skeleton);
+ transceive_skeleton = NULL;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include <vconf.h>
+
+#include "net_nfc_typedef.h"
+
+#include "net_nfc_server_vconf.h"
+#include "net_nfc_server_common.h"
+#include "net_nfc_server_manager.h"
+
+#include "net_nfc_debug_internal.h"
+
+static gboolean powered_off_by_flightmode = FALSE;
+
+static void vconf_set_flight_mode(int boolval);
+
+static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
+ void *user_data);
+
+static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
+ void *user_data);
+
+
+static void vconf_set_flight_mode(int boolval)
+{
+ gint result;
+
+ /* set predefined item */
+ result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, boolval);
+ if (result != 0)
+ {
+ DEBUG_ERR_MSG("can not set to %d: %s",
+ boolval,
+ "VCONKEY_NFC_PREDEFINED_ITEM_STATE");
+ }
+}
+
+static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
+ void *user_data)
+{
+ gint state = 0;
+ gint pm_state = 0;
+ gint result;
+
+ result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
+ if (result != 0)
+ DEBUG_ERR_MSG("can not get %s", "VCONFKEY_NFC_STATE");
+
+ if (state == false)
+ {
+ DEBUG_MSG("NFC off");
+ return;
+ }
+
+ result = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
+ if (result != 0)
+ DEBUG_ERR_MSG("can not get %s", "VCONFKEY_PM_STATE");
+
+ DEBUG_SERVER_MSG("pm_state : %d", pm_state);
+
+ if (pm_state == VCONFKEY_PM_STATE_NORMAL ||
+ pm_state == VCONFKEY_PM_STATE_LCDOFF)
+ {
+ net_nfc_server_restart_polling_loop();
+ }
+}
+
+static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
+ void *user_data)
+{
+ gint flight_mode = 0;
+ gint nfc_state = 0;
+
+ gint result = 0;
+
+ result = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
+ if (result != 0)
+ {
+ DEBUG_ERR_MSG("Can not get %s",
+ "VCONFKEY_TELEPHONY_FLIGHT_MODE");
+ }
+
+ DEBUG_SERVER_MSG("flight mode %d", flight_mode);
+
+ result = vconf_get_bool(VCONFKEY_NFC_STATE, &nfc_state);
+ if (result != 0)
+ {
+ DEBUG_ERR_MSG("Can not get %s",
+ "VCONFKEY_NET_STATE");
+ }
+
+ DEBUG_SERVER_MSG("nfc_state %d", nfc_state);
+ DEBUG_SERVER_MSG("powerd_off_by_flightmode %d",
+ powered_off_by_flightmode);
+
+ if (flight_mode) /* turn on flight mode */
+ {
+ /* nfc is already disabled ignore it */
+ if (nfc_state == VCONFKEY_NFC_STATE_OFF)
+ return;
+
+ DEBUG_SERVER_MSG("Turning NFC off");
+ net_nfc_server_manager_set_active(FALSE);
+
+ powered_off_by_flightmode = TRUE;
+
+ vconf_set_flight_mode(0);
+ }
+ else /* turn off flight mode */
+ {
+ /* nfc is already enabled, ignre it */
+ if (nfc_state == VCONFKEY_NFC_STATE_ON)
+ return;
+
+ if (powered_off_by_flightmode == FALSE)
+ return;
+
+ DEBUG_SERVER_MSG("Turning NFC on");
+ net_nfc_server_manager_set_active(TRUE);
+
+ powered_off_by_flightmode = FALSE;
+
+ vconf_set_flight_mode(1);
+ }
+}
+
+void net_nfc_server_vconf_init(void)
+{
+ vconf_notify_key_changed(VCONFKEY_PM_STATE,
+ net_nfc_server_vconf_pm_state_changed,
+ NULL);
+
+ vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+ net_nfc_server_vconf_flight_mode_changed,
+ NULL);
+}
+
+void net_nfc_server_vconf_deinit(void)
+{
+ vconf_ignore_key_changed(VCONFKEY_PM_STATE,
+ net_nfc_server_vconf_pm_state_changed);
+
+ vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+ net_nfc_server_vconf_flight_mode_changed);
+}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <pthread.h>
-#include <malloc.h>
-
-#include "vconf.h"
-
-#include "net_nfc_controller_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_service_private.h"
-#include "net_nfc_service_se_private.h"
-#include "net_nfc_app_util_private.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_server_dispatcher_private.h"
-#include "net_nfc_manager_util_private.h"
-#include "net_nfc_service_tag_private.h"
-#include "net_nfc_service_llcp_private.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_server_context_private.h"
-
-/* static variable */
-
-/* static callback function */
-
-/* static function */
-
-#ifndef BROADCAST_MESSAGE
-extern uint8_t g_se_cur_type;
-extern uint8_t g_se_cur_mode;
-
-static bool _net_nfc_service_check_internal_ese_detected()
-{
- if (g_se_cur_type == SECURE_ELEMENT_TYPE_ESE && g_se_cur_mode == SECURE_ELEMENT_WIRED_MODE)
- {
- return true;
- }
-
- return false;
-}
-#endif
-
-static void _net_nfc_service_show_exception_msg(char* msg);
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void net_nfc_service_target_detected_cb(void *info, void *user_context)
-{
- net_nfc_request_msg_t *req_msg = (net_nfc_request_msg_t *)info;
-
- if (info == NULL)
- return;
-
- if (req_msg->request_type == NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP)
- {
- net_nfc_dispatcher_queue_push(req_msg);
- }
-#ifdef BROADCAST_MESSAGE
- else
- {
- net_nfc_server_set_tag_info(info);
-
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED;
- net_nfc_dispatcher_queue_push(req_msg);
- }
-#else
- else if (net_nfc_server_get_current_client_context(&client_context) == true &&
- net_nfc_server_check_client_is_running(&client_context) == true)
- {
- net_nfc_request_target_detected_t *detail = (net_nfc_request_target_detected_t *)req_msg;
-
- /* If target detected, sound should be played. */
- net_nfc_manager_util_play_sound(NET_NFC_TASK_START);
-
- net_nfc_server_set_tag_info(info);
-
- if (!_net_nfc_service_check_internal_ese_detected())
- {
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_TARGET_DETECTED;
- }
- else
- {
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_SLAVE_ESE_DETECTED;
-
- (detail->handle)->connection_type = NET_NFC_SE_CONNECTION;
- }
-
- net_nfc_server_set_current_client_target_handle(client_context, detail->handle);
-
- net_nfc_dispatcher_queue_push(req_msg);
-
- DEBUG_SERVER_MSG("current client is listener. stand alone mode will be activated");
- }
- else
- {
- /* If target detected, sound should be played. */
- net_nfc_manager_util_play_sound(NET_NFC_TASK_START);
-
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED;
- net_nfc_dispatcher_queue_push(req_msg);
- }
-#endif
-}
-
-void net_nfc_service_se_transaction_cb(void *info, void *user_context)
-{
- net_nfc_request_se_event_t *req_msg = (net_nfc_request_se_event_t *)info;
-
- DEBUG_SERVER_MSG("se event [%d]", req_msg->request_type);
-
- net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)req_msg);
-}
-
-void net_nfc_service_llcp_event_cb(void* info, void* user_context)
-{
- net_nfc_request_llcp_msg_t *req_msg = (net_nfc_request_llcp_msg_t *)info;
-
- if (req_msg == NULL)
- {
- DEBUG_SERVER_MSG("req msg is null");
- return;
- }
-
- if (req_msg->request_type == NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT)
- {
- net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)req_msg;
- detail->trans_param = user_context;
- }
-
- req_msg->user_param = (uint32_t)user_context;
-
- net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)req_msg);
-}
-
-static bool _is_isp_dep_ndef_formatable(net_nfc_target_handle_s *handle, int dev_type)
-{
- bool result = false;
- uint8_t cmd[] = { 0x90, 0x60, 0x00, 0x00, 0x00 };
- net_nfc_transceive_info_s info;
- data_s *response = NULL;
- net_nfc_error_e error = NET_NFC_OK;
-
- info.dev_type = dev_type;
- info.trans_data.buffer = cmd;
- info.trans_data.length = sizeof(cmd);
-
- if (net_nfc_controller_transceive(handle, &info, &response, &error) == true)
- {
- if (response != NULL)
- {
- if (response->length == 9 && response->buffer[7] == (uint8_t)0x91 &&
- response->buffer[8] == (uint8_t)0xAF)
- {
- result = true;
- }
- else
- {
- DEBUG_ERR_MSG("Unknown response....");
- DEBUG_MSG_PRINT_BUFFER(response->buffer, response->length);
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_transceive response is null");
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_transceive is failed, [%d]", error);
- }
-
- return result;
-}
-
-static net_nfc_error_e _read_ndef_message(net_nfc_target_handle_s *handle, int dev_type, data_s **read_ndef)
-{
- net_nfc_error_e result = NET_NFC_OK;
- data_s *temp = NULL;
-
- if (handle == NULL || read_ndef == NULL)
- return NET_NFC_INVALID_PARAM;
-
- *read_ndef = NULL;
-
- /* Desfire */
- if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC)
- {
- DEBUG_SERVER_MSG("DESFIRE : check ISO-DEP ndef formatable");
-
- if (_is_isp_dep_ndef_formatable(handle, dev_type) == true)
- {
- DEBUG_SERVER_MSG("DESFIRE : ISO-DEP ndef formatable");
-
- if (!net_nfc_controller_connect(handle, &result))
- {
- DEBUG_ERR_MSG("net_nfc_controller_connect failed & Retry Polling!!");
-
- if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME,
- NET_NFC_ALL_ENABLE, &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
-
- return NET_NFC_TAG_READ_FAILED;
- }
- }
- else
- {
- DEBUG_ERR_MSG("DESFIRE : ISO-DEP ndef not formatable");
-
- return NET_NFC_TAG_READ_FAILED;
- }
- }
-
- if (net_nfc_controller_read_ndef(handle, &temp, &result) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_read_ndef success");
-
- if (dev_type == NET_NFC_MIFARE_DESFIRE_PICC)
- {
- if (!net_nfc_controller_connect(handle, &result))
- {
- DEBUG_ERR_MSG("net_nfc_controller_connect failed & Retry Polling!!");
-
- if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
-
- net_nfc_util_free_data(temp);
- _net_nfc_util_free_mem(temp);
-
- return NET_NFC_TAG_READ_FAILED;
- }
- }
-
- *read_ndef = temp;
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed [%d]", result);
- }
-
- return result;
-}
-
-#ifndef BROADCAST_MESSAGE
-bool net_nfc_service_standalone_mode_target_detected(net_nfc_request_msg_t* msg)
-{
- net_nfc_request_target_detected_t* stand_alone = (net_nfc_request_target_detected_t *)msg;
- net_nfc_error_e error_status = NET_NFC_OK;
-
- data_s *recv_data = NULL;
-
- DEBUG_SERVER_MSG("*** Detected! type [0x%X)] ***", stand_alone->devType);
-
- switch (stand_alone->devType)
- {
- case NET_NFC_NFCIP1_TARGET :
- case NET_NFC_NFCIP1_INITIATOR :
- {
- DEBUG_SERVER_MSG(" LLCP is detected");
-
- net_nfc_service_llcp_process(stand_alone->handle, stand_alone->devType, &error_status);
-
- malloc_trim(0);
- return true;
- }
- break;
-
- default :
- {
- DEBUG_SERVER_MSG(" PICC or PCD is detectd.");
- recv_data = net_nfc_service_tag_process(stand_alone->handle, stand_alone->devType, &error_status);
- }
- break;
- }
-
- if (recv_data != NULL)
- {
- net_nfc_service_msg_processing(recv_data);
- }
- else
- {
- if (((stand_alone->devType == NET_NFC_NFCIP1_INITIATOR) || (stand_alone->devType == NET_NFC_NFCIP1_TARGET)))
- {
- DEBUG_SERVER_MSG("p2p operation. recv data is NULL");
- }
- else
- {
- if (error_status == NET_NFC_NO_NDEF_SUPPORT)
- {
- DEBUG_SERVER_MSG("device type = [%d], it has null data", stand_alone->devType);
-
- /* launch empty tag */
- uint8_t empty[] = { 0xd0, 0x00, 0x00 }; /* raw-data of empty ndef-message */
- data_s rawdata = { &empty, sizeof(empty) };
-
- net_nfc_service_msg_processing(&rawdata);
- }
- else
- {
- _net_nfc_service_show_exception_msg("Try again");
- }
- }
- }
-
- if (stand_alone->devType != NET_NFC_NFCIP1_INITIATOR && stand_alone->devType != NET_NFC_NFCIP1_TARGET)
- {
- net_nfc_request_watch_dog_t* watch_dog_msg = NULL;
-
- _net_nfc_util_alloc_mem(watch_dog_msg, sizeof(net_nfc_request_watch_dog_t));
-
- if (watch_dog_msg != NULL)
- {
- watch_dog_msg->length = sizeof(net_nfc_request_watch_dog_t);
- watch_dog_msg->request_type = NET_NFC_MESSAGE_SERVICE_WATCH_DOG;
- watch_dog_msg->devType = stand_alone->devType;
- watch_dog_msg->handle = stand_alone->handle;
-
- net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)watch_dog_msg);
- }
- }
-
- DEBUG_SERVER_MSG("stand alone mode is end");
- malloc_trim(0);
-
- return true;
-}
-#endif
-
-bool net_nfc_service_slave_mode_target_detected(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_target_detected_t *detail_msg = (net_nfc_request_target_detected_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
- bool success = true;
-
- DEBUG_SERVER_MSG("target detected callback for client, device type = [%d]", detail_msg->devType);
-
- if (detail_msg == NULL)
- {
- return false;
- }
-
- if (detail_msg->devType != NET_NFC_NFCIP1_TARGET && detail_msg->devType != NET_NFC_NFCIP1_INITIATOR)
- {
- net_nfc_response_tag_discovered_t resp_msg = { 0, };
- int request_type = NET_NFC_MESSAGE_TAG_DISCOVERED;
- data_s *recv_data = NULL;
-
- if (!net_nfc_controller_connect(detail_msg->handle, &result))
- {
- DEBUG_ERR_MSG("connect failed & Retry Polling!!");
-
- if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
- return false;
- }
-
-#ifdef BROADCAST_MESSAGE
- net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED);
-#endif
- DEBUG_SERVER_MSG("tag is connected");
-
- uint8_t ndef_card_state = 0;
- int max_data_size = 0;
- int real_data_size = 0;
-
- if (net_nfc_controller_check_ndef(detail_msg->handle, &ndef_card_state, &max_data_size, &real_data_size, &result) == true)
- {
- resp_msg.ndefCardState = ndef_card_state;
- resp_msg.maxDataSize = max_data_size;
- resp_msg.actualDataSize = real_data_size;
- resp_msg.is_ndef_supported = 1;
- }
-
- resp_msg.devType = detail_msg->devType;
- resp_msg.handle = detail_msg->handle;
- resp_msg.number_of_keys = detail_msg->number_of_keys;
- resp_msg.raw_data.length = 0;
-
- net_nfc_util_duplicate_data(&resp_msg.target_info_values, &detail_msg->target_info_values);
-
- if (resp_msg.is_ndef_supported)
- {
- DEBUG_SERVER_MSG("support NDEF");
-
- if ((result = _read_ndef_message(detail_msg->handle, detail_msg->devType, &recv_data)) == NET_NFC_OK &&
- recv_data != NULL)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_read_ndef success");
-#ifdef BROADCAST_MESSAGE
- net_nfc_service_msg_processing(recv_data);
-#endif
- resp_msg.raw_data.length = recv_data->length;
- success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t),
- (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length,
- (void *)(recv_data->buffer), recv_data->length, NULL);
-
- net_nfc_util_free_data(recv_data);
- _net_nfc_util_free_mem(recv_data);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_read_ndef failed");
-
- success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t),
- (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, NULL);
- }
- }
- else
- {
- DEBUG_SERVER_MSG("not support NDEF");
-#ifdef BROADCAST_MESSAGE
- /* launch empty tag */
- uint8_t empty[] = { 0xd0, 0x00, 0x00 }; /* raw-data of empty ndef-message */
- data_s rawdata = { empty, sizeof(empty) };
-
- net_nfc_service_msg_processing(&rawdata);
-#endif
- success = net_nfc_broadcast_response_msg(request_type, (void *)&resp_msg, sizeof(net_nfc_response_tag_discovered_t),
- (void *)(resp_msg.target_info_values.buffer), resp_msg.target_info_values.length, NULL);
- }
-
- net_nfc_util_free_data(&resp_msg.target_info_values);
-
- DEBUG_SERVER_MSG("turn on watch dog");
-
- net_nfc_request_watch_dog_t* watch_dog_msg = NULL;
-
- _net_nfc_util_alloc_mem(watch_dog_msg, sizeof(net_nfc_request_watch_dog_t));
- if (watch_dog_msg != NULL)
- {
- watch_dog_msg->length = sizeof(net_nfc_request_watch_dog_t);
- watch_dog_msg->request_type = NET_NFC_MESSAGE_SERVICE_WATCH_DOG;
- watch_dog_msg->devType = detail_msg->devType;
- watch_dog_msg->handle = detail_msg->handle;
-
- net_nfc_dispatcher_queue_push((net_nfc_request_msg_t *)watch_dog_msg);
- }
- }
- else /* LLCP */
- {
- net_nfc_error_e error_status = NET_NFC_OK;
-
- net_nfc_service_llcp_process(detail_msg->handle, detail_msg->devType, &error_status);
- }
-
- /* If target detected, sound should be played. */
- net_nfc_manager_util_play_sound(NET_NFC_TASK_START);
-
- return success;
-}
-
-bool net_nfc_service_termination(net_nfc_request_msg_t* msg)
-{
- net_nfc_error_e result;
-
- if (net_nfc_controller_is_ready(&result) == true)
- {
- }
- else
- {
- DEBUG_SERVER_MSG("Not initialized");
- net_nfc_controller_init(&result);
- }
-
- if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, NET_NFC_ALL_DISABLE, &result) != true)
- {
- DEBUG_SERVER_MSG("failed to discover off %d", result);
- }
-
- if (net_nfc_controller_set_secure_element_mode(NET_NFC_SE_CMD_UICC_ON, SECURE_ELEMENT_VIRTUAL_MODE, &result) != true)
- {
- DEBUG_SERVER_MSG("failed to set se mode to default mode: %d", result);
- }
-
- return true;
-}
-
-void net_nfc_service_msg_processing(data_s* data)
-{
- if (data != NULL)
- {
- net_nfc_app_util_process_ndef(data);
- }
- else
- {
- _net_nfc_service_show_exception_msg("unknown type tag");
- }
-}
-
-static void _net_nfc_service_show_exception_msg(char* msg)
-{
- bundle *kb = NULL;
-
- kb = bundle_create();
- bundle_add(kb, "type", "default");
- bundle_add(kb, "text", msg);
-
- net_nfc_app_util_aul_launch_app("com.samsung.nfc-app", kb); /* empty_tag */
-
- bundle_free(kb);
-}
-
-void net_nfc_service_is_tag_connected(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_is_tag_connected_t *detail = (net_nfc_request_is_tag_connected_t *)msg;
- net_nfc_current_target_info_s *target_info;
-
- target_info = net_nfc_server_get_tag_info();
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_is_tag_connected_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_is_tag_connected_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
-
- if (target_info != NULL)
- {
- resp.result = NET_NFC_OK;
- resp.devType = target_info->devType;
- }
- else
- {
- resp.result = NET_NFC_NOT_CONNECTED;
- resp.devType = NET_NFC_UNKNOWN_TARGET;
- }
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_is_tag_connected_t), NULL);
- }
-}
-
-void net_nfc_service_get_current_tag_info(net_nfc_request_msg_t *msg)
-{
- net_nfc_response_get_current_tag_info_t resp = { 0, };
- net_nfc_request_get_current_tag_info_t *detail = (net_nfc_request_get_current_tag_info_t *)msg;
- net_nfc_current_target_info_s *target_info = NULL;
- net_nfc_error_e result = NET_NFC_OK;
-
- resp.length = sizeof(net_nfc_response_get_current_tag_info_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
-
- target_info = net_nfc_server_get_tag_info();
- if (target_info != NULL)
- {
- bool success = true;
- data_s *recv_data = NULL;
-
- if (target_info->devType != NET_NFC_NFCIP1_TARGET && target_info->devType != NET_NFC_NFCIP1_INITIATOR)
- {
-#ifdef BROADCAST_MESSAGE
- net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED);
-#endif
- DEBUG_SERVER_MSG("tag is connected");
-
- uint8_t ndef_card_state = 0;
- int max_data_size = 0;
- int real_data_size = 0;
-
- if (net_nfc_controller_check_ndef(target_info->handle,
- &ndef_card_state, &max_data_size, &real_data_size, &result) == true)
- {
- resp.ndefCardState = ndef_card_state;
- resp.maxDataSize = max_data_size;
- resp.actualDataSize = real_data_size;
- resp.is_ndef_supported = 1;
- }
-
- resp.devType = target_info->devType;
- resp.handle = target_info->handle;
- resp.number_of_keys = target_info->number_of_keys;
-
- net_nfc_util_duplicate_data(&resp.target_info_values, &target_info->target_info_values);
-
- if (resp.is_ndef_supported)
- {
- if (net_nfc_controller_read_ndef(target_info->handle, &recv_data, &(resp.result)) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is success");
-
- resp.raw_data.length = recv_data->length;
-
- success = net_nfc_send_response_msg(msg->client_fd, msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t),
- (void *)(resp.target_info_values.buffer), resp.target_info_values.length,
- (void *)(recv_data->buffer), recv_data->length, NULL);
- }
- else
- {
- DEBUG_SERVER_MSG("net_nfc_controller_read_ndef is fail");
-
- resp.raw_data.length = 0;
-
- success = net_nfc_send_response_msg(msg->client_fd, msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t),
- (void *)(resp.target_info_values.buffer), resp.target_info_values.length, NULL);
- }
- }
- else
- {
- resp.raw_data.length = 0;
-
- success = net_nfc_send_response_msg(msg->client_fd, msg->request_type, (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t),
- (void *)(resp.target_info_values.buffer), resp.target_info_values.length, NULL);
- }
-
- net_nfc_util_free_data(&resp.target_info_values);
- }
- else
- {
- /* LLCP */
- resp.result = NET_NFC_NOT_CONNECTED;
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), NULL);
- }
- }
- else
- {
- resp.result = NET_NFC_NOT_CONNECTED;
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_get_current_tag_info_t), NULL);
- }
-}
-
-void net_nfc_service_get_current_target_handle(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_get_current_target_handle_t *detail = (net_nfc_request_get_current_target_handle_t *)msg;
- net_nfc_current_target_info_s *target_info = NULL;
-
- target_info = net_nfc_server_get_tag_info();
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_get_current_target_handle_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_get_current_target_handle_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
-
- if (target_info != NULL)
- {
- resp.handle = target_info->handle;
- resp.devType = target_info->devType;
- resp.result = NET_NFC_OK;
- }
- else
- {
- resp.result = NET_NFC_NOT_CONNECTED;
- }
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_get_current_target_handle_t), NULL);
- }
-}
-
-void net_nfc_service_deinit(net_nfc_request_msg_t *msg)
-{
- net_nfc_error_e result;
-
- result = net_nfc_service_se_change_se(SECURE_ELEMENT_TYPE_INVALID);
-
- net_nfc_server_free_current_tag_info();
-
- if (net_nfc_controller_deinit() == TRUE)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_deinit success [%d]", result);
-
- /*vconf off*/
- if (vconf_set_bool(VCONFKEY_NFC_STATE, FALSE) != 0)
- {
- DEBUG_ERR_MSG("vconf_set_bool failed");
- }
-
- net_nfc_response_test_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_test_t);
- resp.flags = msg->flags;
- resp.result = NET_NFC_OK;
- resp.trans_param = (void *)msg->user_param;
-
- net_nfc_broadcast_response_msg(msg->request_type, (void *)&resp,
- sizeof(net_nfc_response_test_t), NULL);
- }
- else
- {
- DEBUG_SERVER_MSG("net_nfc_controller_deinit failed");
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_test_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_test_t);
- resp.flags = msg->flags;
- resp.result = NET_NFC_UNKNOWN_ERROR;
- resp.trans_param = (void *)msg->user_param;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_test_t), NULL);
- }
- }
-}
-
-void net_nfc_service_init(net_nfc_request_msg_t *msg)
-{
- net_nfc_error_e result;
-
- if (net_nfc_controller_init(&result) == true)
- {
- net_nfc_llcp_config_info_s config = { 128, 1, 100, 0 };
-
- if (net_nfc_controller_register_listener(net_nfc_service_target_detected_cb,
- net_nfc_service_se_transaction_cb, net_nfc_service_llcp_event_cb, &result) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_register_listener Success!!");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_register_listener failed [%d]", result);
- }
-
- if (net_nfc_controller_llcp_config(&config, &result) == true)
- {
- /*We need to check the stack that supports the llcp or not.*/
- DEBUG_SERVER_MSG("llcp is enabled");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_config failed [%d]", result);
- }
-
- result = net_nfc_service_se_change_se(SECURE_ELEMENT_TYPE_UICC);
-
- if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG,
- NET_NFC_ALL_ENABLE, &result) == true)
- {
- DEBUG_SERVER_MSG("now, nfc is ready");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_confiure_discovery failed [%d]", result);
- }
-
- /*Send the Init Success Response Msg*/
- {
- net_nfc_response_test_t resp = { 0, };
-
- DEBUG_SERVER_MSG("net_nfc_controller_init success [%d]", result);
-
- resp.length = sizeof(net_nfc_response_test_t);
- resp.flags = msg->flags;
- resp.result = NET_NFC_OK;
- resp.trans_param = (void *)msg->user_param;
-
- /*vconf on*/
- if (vconf_set_bool(VCONFKEY_NFC_STATE, TRUE) != 0)
- {
- DEBUG_ERR_MSG("vconf_set_bool failed");
- }
-
- net_nfc_broadcast_response_msg(msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_test_t), NULL);
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_init failed [%d]", result);
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_test_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_test_t);
- resp.flags = msg->flags;
- resp.result = result;
- resp.trans_param = (void *)msg->user_param;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_test_t), NULL);
- }
- }
-}
-
-void net_nfc_service_restart_polling(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_msg_t *discovery_req = (net_nfc_request_msg_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
- int pm_state = 0;
- int set_config = 0;
-
- pm_state = discovery_req->user_param;
-
- DEBUG_SERVER_MSG("NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP PM State = [%d]", pm_state);
-
- if (pm_state == 1)
- {
- set_config = NET_NFC_ALL_ENABLE;
- }
- else if (pm_state == 3)
- {
- set_config = NET_NFC_ALL_DISABLE;
- }
- else
- {
- DEBUG_SERVER_MSG("Do not anything!!");
- }
-
- if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, set_config, &result) == true)
- {
- DEBUG_SERVER_MSG("now, nfc polling loop is running again");
- }
-}
-
-void net_nfc_service_get_server_state(net_nfc_request_msg_t *msg)
-{
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_get_server_state_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_get_server_state_t);
- resp.flags = msg->flags;
- resp.state = net_nfc_server_get_server_state();
- resp.result = NET_NFC_OK;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_get_server_state_t), NULL);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <pthread.h>
-#include <malloc.h>
-#include <netinet/in.h>
-
-#include "net_nfc_controller_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_service_private.h"
-#include "net_nfc_app_util_private.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_server_dispatcher_private.h"
-#include "net_nfc_manager_util_private.h"
-#include "net_nfc_service_llcp_private.h"
-#include "net_nfc_service_llcp_handover_private.h"
-#include "net_nfc_server_context_private.h"
-
-static uint8_t snep_server_buffer[SNEP_MAX_BUFFER] = { 0, };
-static uint8_t snep_client_buffer[SNEP_MAX_BUFFER] = { 0, };
-
-static data_s snep_server_data = { snep_server_buffer, SNEP_MAX_BUFFER };
-static data_s snep_client_data = { snep_client_buffer, SNEP_MAX_BUFFER };
-
-static net_nfc_llcp_state_t current_llcp_client_state;
-static net_nfc_llcp_state_t current_llcp_server_state;
-
-/* static callback function */
-
-#if 0
-net_nfc_error_e _net_nfc_service_llcp_get_server_configuration_value(char* service_name, char* attr_name, char* attr_value);
-#endif
-static bool _net_nfc_service_llcp_state_process(net_nfc_request_msg_t *msg);
-
-static bool _net_nfc_service_llcp_snep_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result);
-static bool _net_nfc_service_llcp_client(net_nfc_llcp_state_t * state, net_nfc_error_e* result);
-static data_s* _net_nfc_service_llcp_snep_create_msg(snep_command_field_e resp_field, data_s* information);
-static net_nfc_error_e _net_nfc_service_llcp_snep_check_req_msg(data_s* snep_msg, uint8_t* resp_code);
-static net_nfc_error_e _net_nfc_service_llcp_snep_get_code(data_s* snep_msg, uint8_t* code);
-static net_nfc_error_e _net_nfc_service_llcp_snep_get_information_length(data_s* snep_msg, uint32_t* length);
-static net_nfc_error_e _net_nfc_service_llcp_snep_check_resp_msg(data_s* snep_msg);
-
-static bool _net_nfc_service_llcp_npp_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result);
-static data_s* _net_nfc_service_llcp_npp_create_msg(data_s* information);
-static net_nfc_error_e _net_nfc_service_llcp_npp_check_req_msg(data_s* npp_msg, uint8_t* resp_code);
-static net_nfc_error_e _net_nfc_service_llcp_npp_get_information_length(data_s* npp_msg, uint32_t* length);
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-GList * state_list = NULL;
-static bool net_nfc_service_llcp_is_valid_state(net_nfc_llcp_state_t * state)
-{
- if (g_list_find(state_list, state) != NULL)
- {
- return true;
- }
- return false;
-}
-void net_nfc_service_llcp_remove_state(net_nfc_llcp_state_t * state)
-{
- if (state != NULL)
- {
- state_list = g_list_remove(state_list, state);
- }
-}
-void net_nfc_service_llcp_add_state(net_nfc_llcp_state_t * state)
-{
- if (state != NULL)
- {
- state_list = g_list_append(state_list, state);
- }
-}
-
-bool net_nfc_service_llcp_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result)
-{
- *result = NET_NFC_OK;
-
- DEBUG_SERVER_MSG("connection type = [%d]", handle->connection_type);
-
- if (devType == NET_NFC_NFCIP1_TARGET)
- {
- DEBUG_SERVER_MSG("trying to connect to tag = [0x%p]", handle);
-
- if (net_nfc_controller_connect(handle, result) != true)
- {
- DEBUG_SERVER_MSG("connect failed");
-
- if (net_nfc_controller_confiure_discovery(NET_NFC_DISCOVERY_MODE_RESUME, NET_NFC_ALL_ENABLE, result) == false)
- {
- net_nfc_controller_exception_handler();
-
- }
-
- return false;
- }
- }
-
- DEBUG_SERVER_MSG("check LLCP");
-
- if (net_nfc_controller_llcp_check_llcp(handle, result) == true)
- {
- DEBUG_SERVER_MSG("activate LLCP");
- if (net_nfc_controller_llcp_activate_llcp(handle, result) == true)
- {
-#ifdef SUPPORT_CONFIG_FILE
- char value[64] =
- { 0,};
- if (net_nfc_service_get_configuration_value("service", "exchange_service", value) == NET_NFC_OK)
- {
- if (strcmp(value, "true") == 0)
- {
- net_nfc_llcp_state_t * exchange_state_server = NULL;
- _net_nfc_util_alloc_mem(exchange_state_server, sizeof (net_nfc_llcp_state_t));
-
- exchange_state_server->handle = handle;
- exchange_state_server->state = NET_NFC_STATE_EXCHANGER_SERVER;
- exchange_state_server->step = NET_NFC_LLCP_STEP_01;
- exchange_state_server->user_data = NULL;
-
- net_nfc_service_llcp_add_state(exchange_state_server);
-
- if (_net_nfc_service_llcp_snep_server(exchange_state_server, result) == false)
- {
- return false;
- }
-
- handle->app_type = exchange_state_server->type_app_protocol;
- DEBUG_SERVER_MSG("handle->app_type = [%d]", handle->app_type);
- }
- else
- {
- DEBUG_SERVER_MSG("llcp exchange service is trunned off");
- }
- }
- else
- {
- net_nfc_llcp_state_t * exchange_state_server = NULL;
- _net_nfc_util_alloc_mem(exchange_state_server, sizeof (net_nfc_llcp_state_t));
-
- exchange_state_server->handle = handle;
- exchange_state_server->state = NET_NFC_STATE_EXCHANGER_SERVER;
- exchange_state_server->step = NET_NFC_LLCP_STEP_01;
- exchange_state_server->user_data = NULL;
-
- net_nfc_service_llcp_add_state(exchange_state_server);
-
- if (_net_nfc_service_llcp_npp_server(exchange_state_server, result) == false)
- {
- DEBUG_SERVER_MSG("ERROR!!!!!!!!!!!!!!!");
- return false;
- }
- else
- {
- handle->app_type = exchange_state_server->type_app_protocol;
- DEBUG_SERVER_MSG("handle->app_type = [%d]", handle->app_type);
- }
- }
-
- memset(value, 0x00, 64);
-
- if (net_nfc_service_get_configuration_value("service", "connection_handover", value) == NET_NFC_OK)
- {
- if (strcmp(value, "true") == 0)
- {
- net_nfc_llcp_state_t * conn_handover_selector = NULL;
- _net_nfc_util_alloc_mem(conn_handover_selector, sizeof (net_nfc_llcp_state_t));
-
- conn_handover_selector->handle = handle;
- conn_handover_selector->state = NET_NFC_STATE_CONN_HANDOVER_SELECT;
- conn_handover_selector->step = NET_NFC_LLCP_STEP_01;
- conn_handover_selector->user_data = NULL;
-
- net_nfc_service_llcp_add_state(conn_handover_selector);
-
- if (_net_nfc_service_llcp_stand_alone_conn_handover_selector(conn_handover_selector, result) == false)
- {
- return false;
- }
- }
- else
- {
- DEBUG_SERVER_MSG("llcp connection handover is trunned off");
- }
- }
-#else/* Use the NPP & the SNEP FOR LLCP , Handover*/
- /* NPP */
- net_nfc_llcp_state_t * exchange_state_server_NPP = NULL;
- _net_nfc_util_alloc_mem(exchange_state_server_NPP, sizeof (net_nfc_llcp_state_t));
- exchange_state_server_NPP->handle = handle;
- exchange_state_server_NPP->state = NET_NFC_STATE_EXCHANGER_SERVER_NPP;
- exchange_state_server_NPP->step = NET_NFC_LLCP_STEP_01;
- exchange_state_server_NPP->user_data = NULL;
-
- net_nfc_service_llcp_add_state(exchange_state_server_NPP);
-
- if (_net_nfc_service_llcp_npp_server(exchange_state_server_NPP, result) == false)
- {
- return false;
- }
-
- /* SNEP */
- net_nfc_llcp_state_t * exchange_state_server_SNEP = NULL;
- _net_nfc_util_alloc_mem(exchange_state_server_SNEP, sizeof (net_nfc_llcp_state_t));
- exchange_state_server_SNEP->handle = handle;
- exchange_state_server_SNEP->state = NET_NFC_STATE_EXCHANGER_SERVER;
- exchange_state_server_SNEP->step = NET_NFC_LLCP_STEP_01;
- exchange_state_server_SNEP->user_data = NULL;
-
- net_nfc_service_llcp_add_state(exchange_state_server_SNEP);
-
- if (_net_nfc_service_llcp_snep_server(exchange_state_server_SNEP, result) == false)
- {
- return false;
- }
-
- net_nfc_llcp_state_t * conn_handover_selector = NULL;
- _net_nfc_util_alloc_mem(conn_handover_selector, sizeof (net_nfc_llcp_state_t));
- conn_handover_selector->handle = handle;
- conn_handover_selector->state = NET_NFC_STATE_CONN_HANDOVER_SELECT;
- conn_handover_selector->step = NET_NFC_LLCP_STEP_01;
- conn_handover_selector->user_data = NULL;
-
- net_nfc_service_llcp_add_state(conn_handover_selector);
-
- if (net_nfc_service_llcp_connection_handover_selector(conn_handover_selector, result) == false)
- {
- return false;
- }
-#endif
- }
- }
-
- DEBUG_SERVER_MSG("handle->app_type = [%d]", handle->app_type);
-
- {
- net_nfc_response_p2p_discovered_t req_msg = { 0, };
- req_msg.handle = handle;
- req_msg.result = NET_NFC_OK;
-
- net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_DISCOVERED, &req_msg, sizeof(net_nfc_response_p2p_discovered_t), NULL);
- }
-
- DEBUG_SERVER_MSG("stand alone llcp service is finished");
-
- return false;
-}
-
-static bool _net_nfc_service_llcp_state_process(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;
- net_nfc_llcp_state_t *state = NULL;
- bool result;
- net_nfc_error_e error;
-
- DEBUG_SERVER_MSG("llcp service by nfc-manager");
-
- if (msg == NULL)
- {
- DEBUG_SERVER_MSG("msg is NULL");
- return false;
- }
-
- state = (net_nfc_llcp_state_t *)(llcp_msg->user_param);
-
- if (state == NULL || !net_nfc_service_llcp_is_valid_state(state))
- {
- DEBUG_SERVER_MSG("state is NULL");
- return false;
- }
-
- switch (msg->request_type)
- {
- case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR :
- case NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR :
- state->step = NET_NFC_STATE_SOCKET_ERROR;
- break;
-
- default :
- break;
- }
-
- state->prev_result = llcp_msg->result;
-
- DEBUG_SERVER_MSG("service type = [%d]", state->state);
-
- switch (state->state)
- {
- case NET_NFC_STATE_EXCHANGER_SERVER :
- DEBUG_SERVER_MSG("exchanger server service");
- net_nfc_server_set_server_state(NET_NFC_SNEP_SERVER_CONNECTED);
- result = _net_nfc_service_llcp_snep_server(state, &error);
- break;
-
- case NET_NFC_STATE_EXCHANGER_CLIENT :
- DEBUG_SERVER_MSG("exchanger client service");
- memcpy(¤t_llcp_client_state, state, sizeof(net_nfc_llcp_state_t));
- result = _net_nfc_service_llcp_client(state, &error);
- break;
-
- case NET_NFC_STATE_EXCHANGER_SERVER_NPP :
- DEBUG_SERVER_MSG("exchanger sesrver npp");
- net_nfc_server_set_server_state(NET_NFC_SNEP_SERVER_CONNECTED);
- result = _net_nfc_service_llcp_npp_server(state, &error);
- break;
-
- case NET_NFC_STATE_CONN_HANDOVER_REQUEST :
- DEBUG_SERVER_MSG("NET_NFC_STATE_CONN_HANDOVER_REQUEST");
- result = net_nfc_service_llcp_connection_handover_requester(state, &error);
- break;
-
- case NET_NFC_STATE_CONN_HANDOVER_SELECT :
- DEBUG_SERVER_MSG("NET_NFC_STATE_CONN_HANDOVER_SELECT");
- result = net_nfc_service_llcp_connection_handover_selector(state, &error);
- break;
-
- default :
- DEBUG_SERVER_MSG("Unkown state state name: %d", state->state);
- return false;
- }
-
- return result;
-}
-
-bool net_nfc_service_llcp_process_accept(net_nfc_request_msg_t *msg)
-{
- bool res = false;
- net_nfc_request_accept_socket_t *accept = (net_nfc_request_accept_socket_t *)msg;
- net_nfc_llcp_state_t *state = NULL;
-
- if (accept == NULL || (void *)accept->user_param == NULL)
- {
- return false;
- }
-
- if (msg->request_type == NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT)
- {
- state = (net_nfc_llcp_state_t *)accept->user_param;
-
- state->incomming_socket = accept->incomming_socket;
-
- DEBUG_SERVER_MSG("Incomming socket : %X", state->incomming_socket);
-
- res = _net_nfc_service_llcp_state_process(msg);
- }
-
- return res;
-}
-
-bool net_nfc_service_llcp_disconnect_target(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;
- net_nfc_target_handle_s *handle = NULL;
-
- DEBUG_SERVER_MSG("llcp disconnect target");
-
- if (llcp_msg == NULL)
- return false;
-
- handle = (net_nfc_target_handle_s *)llcp_msg->user_param;
- if (handle != NULL)
- {
- net_nfc_error_e result = NET_NFC_OK;
-
- if (net_nfc_controller_disconnect(handle, &result) == false)
- {
- if (result != NET_NFC_NOT_CONNECTED)
- {
- net_nfc_controller_exception_handler();
- }
- else
- {
- DEBUG_SERVER_MSG("target was not connected.");
- }
- }
- net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE);
- }
- else
- {
- DEBUG_SERVER_MSG("the target ID = [0x%p] was not connected before. current device may be a TARGET", handle);
- }
-
- {
- net_nfc_response_llcp_detached_t message = { 0, };
- message.result = NET_NFC_OK;
- net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_DETACHED, &message, sizeof(net_nfc_response_llcp_detached_t), NULL);
- }
-
- llcp_msg->user_param = 0; /*detail message should be NULL, because the handle is already freed in disconnect function */
-
- return true;
-}
-
-bool net_nfc_service_llcp_process_socket_error(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- if (net_nfc_server_check_client_is_running(llcp_msg->client_fd))
- {
- /* in case of slave mode */
- net_nfc_response_llcp_socket_error_t *error = (net_nfc_response_llcp_socket_error_t *)llcp_msg->user_param;
-
- error->error = llcp_msg->result;
- DEBUG_SERVER_MSG("Socket error returned [%d]", error->error);
- return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_ERROR, error, sizeof(net_nfc_response_llcp_socket_error_t), NULL);
- }
-
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-bool net_nfc_service_llcp_process_accepted_socket_error(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- if (net_nfc_server_check_client_is_running(llcp_msg->client_fd))
- {
- /* in case of slave mode the error message will be deliver to client stub*/
- net_nfc_response_llcp_socket_error_t *error = (net_nfc_response_llcp_socket_error_t *)llcp_msg->user_param;
- error->error = llcp_msg->result;
- return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_ERROR, error, sizeof(net_nfc_response_llcp_socket_error_t), NULL);
- }
-
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-bool net_nfc_service_llcp_process_connect_socket(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-bool net_nfc_service_llcp_process_connect_sap_socket(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- if (net_nfc_server_check_client_is_running(llcp_msg->client_fd))
- {
- net_nfc_response_connect_sap_socket_t *detail = (net_nfc_response_connect_sap_socket_t *)llcp_msg->user_param;
- detail->result = llcp_msg->result;
- return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_CONNECT_SAP, detail, sizeof(net_nfc_response_connect_sap_socket_t), NULL);
- }
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-bool net_nfc_service_llcp_process_send_socket(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-bool net_nfc_service_llcp_process_send_to_socket(net_nfc_request_msg_t* msg)
-{
- net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- if (net_nfc_server_check_client_is_running(llcp_msg->client_fd))
- {
- /* in case of slave mode the error message will be deliver to client stub*/
- net_nfc_response_send_socket_t *detail = (net_nfc_response_send_socket_t *)llcp_msg->user_param;
- detail->result = llcp_msg->result;
- return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_SEND_TO, detail, sizeof(net_nfc_response_send_socket_t), NULL);
- }
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-bool net_nfc_service_llcp_process_receive_socket(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_msg_t *llcp_msg = (net_nfc_request_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-bool net_nfc_service_llcp_process_receive_from_socket(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- if (net_nfc_server_check_client_is_running(llcp_msg->client_fd))
- {
- net_nfc_response_receive_socket_t *detail = (net_nfc_response_receive_socket_t *)llcp_msg->user_param;
- detail->result = llcp_msg->result;
- return net_nfc_send_response_msg(llcp_msg->client_fd, NET_NFC_MESSAGE_LLCP_RECEIVE_FROM, detail, sizeof(net_nfc_response_receive_socket_t),
- detail->data.buffer, detail->data.length, NULL);
- }
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-bool net_nfc_service_llcp_process_disconnect_socket(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_llcp_msg_t *llcp_msg = (net_nfc_request_llcp_msg_t *)msg;
- bool res = false;
-
- if (msg == NULL)
- return false;
-
- if (net_nfc_server_check_client_is_running(llcp_msg->client_fd))
- {
- net_nfc_response_disconnect_socket_t *detail = (net_nfc_response_disconnect_socket_t *)llcp_msg->user_param;
- detail->result = llcp_msg->result;
- return net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_LLCP_DISCONNECT, detail, sizeof(net_nfc_response_disconnect_socket_t), NULL);
- }
-
- res = _net_nfc_service_llcp_state_process(msg);
-
- llcp_msg->user_param = 0;
-
- return res;
-}
-
-net_nfc_error_e net_nfc_service_send_exchanger_msg(net_nfc_request_p2p_send_t *msg)
-{
- net_nfc_error_e error = NET_NFC_OK;
- data_s *ex_data = NULL;
- net_nfc_llcp_state_t * exchange_state_client = NULL;
-
- DEBUG_SERVER_MSG("send exchanger msg to remote client");
-
- if (msg == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if (msg->handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- _net_nfc_util_alloc_mem(ex_data, sizeof(data_s));
- if (ex_data == NULL)
- {
- DEBUG_SERVER_MSG(" alocation is failed");
- return NET_NFC_ALLOC_FAIL;
- }
- ex_data->length = msg->data.length;
-
- _net_nfc_util_alloc_mem(ex_data->buffer, ex_data->length);
- if (ex_data->buffer == NULL)
- {
- DEBUG_SERVER_MSG(" alocation is failed");
- _net_nfc_util_free_mem(ex_data);
- return NET_NFC_ALLOC_FAIL;
- }
- memcpy(ex_data->buffer, &msg->data.buffer, msg->data.length);
-
- _net_nfc_util_alloc_mem(exchange_state_client, sizeof(net_nfc_llcp_state_t));
- if (exchange_state_client == NULL)
- {
- DEBUG_SERVER_MSG(" alocation is failed");
- _net_nfc_util_free_mem(ex_data);
- _net_nfc_util_free_mem(ex_data->buffer);
- return NET_NFC_ALLOC_FAIL;
- }
-
- exchange_state_client->client_fd = msg->client_fd;
- exchange_state_client->handle = msg->handle;
- exchange_state_client->state = NET_NFC_STATE_EXCHANGER_CLIENT;
- exchange_state_client->step = NET_NFC_LLCP_STEP_01;
- exchange_state_client->payload = ex_data;
- exchange_state_client->user_data = (void *)msg->user_param;
-
- net_nfc_service_llcp_add_state(exchange_state_client);
-
- if (_net_nfc_service_llcp_client(exchange_state_client, &error) == true)
- {
- return NET_NFC_OK;
- }
- else
- {
- DEBUG_SERVER_MSG("exchange client operation is failed");
- return NET_NFC_OPERATION_FAIL;
- }
-}
-
-#if 0
-net_nfc_error_e _net_nfc_service_llcp_get_server_configuration_value(char* service_name, char* attr_name, char* attr_value)
-{
- if (service_name == NULL || attr_name == NULL || attr_value == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- FILE* fp = NULL;
- char file_path[512] = { 0, };
-
- snprintf(file_path, 512, "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH, NET_NFC_MANAGER_DATA_PATH_CONFIG, NET_NFC_MANAGER_LLCP_CONFIG_FILE_NAME);
-
- if ((fp = fopen(file_path, "r")) == NULL)
- {
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- char temp[128] = { 0, };
- while (fgets(temp, sizeof(temp), fp) != NULL)
- {
- net_nfc_util_strip_string(temp, 128);
- char service_name_temp[128] = { 0, };
-
- if (temp[0] == '#')
- continue;
-
- if (temp[0] == '[')
- {
- int i = 0;
- char ch = 0;
-
- while (i < sizeof(temp) && (ch = temp[i++]) != '\n')
- {
- if (ch == ']')
- {
- memcpy(service_name_temp, &temp[1], i - 2);
- break;
- }
- }
-
- if (strlen(service_name_temp) != 0)
- {
- DEBUG_SERVER_MSG("[%s] is found", service_name_temp);
- if (strcmp(service_name_temp, service_name) == 0)
- {
- DEBUG_SERVER_MSG("[%s] and [%s] are matched", service_name_temp, service_name);
-
- while (fgets(temp, sizeof(temp), fp) != NULL)
- {
- if (strcmp(temp, "\n") == 0)
- break;
-
- net_nfc_util_strip_string(temp, 128);
-
- char* pos = NULL;
-
- if ((pos = strstr(temp, "=")) != NULL)
- {
- char attr_name_temp[64] = { 0, };
-
- memcpy(attr_name_temp, temp, pos - temp);
-
- DEBUG_SERVER_MSG("attr_name = [%s]", attr_name);
-
- if (strcmp(attr_name, attr_name_temp) == 0)
- {
- memcpy(attr_value, pos + 1, strlen(pos + 1) - 1);
- DEBUG_SERVER_MSG("attr_value = [%s]", attr_value);
-
- if (fp != NULL)
- fclose(fp);
-
- return NET_NFC_OK;
- }
-
- }
- else
- break;
-
- }
- }
- }
- }
- }
-
- if (fp != NULL)
- fclose(fp);
-
- return NET_NFC_NO_DATA_FOUND;
-
-}
-#endif
-
-static bool _net_nfc_service_llcp_snep_server(net_nfc_llcp_state_t *state, net_nfc_error_e* result)
-{
- bool need_clean_up = false;
-
- if (result == NULL)
- {
- DEBUG_SERVER_MSG("result is NULL");
- return false;
- }
-
- *result = NET_NFC_OK;
-
- switch (state->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- {
- DEBUG_SERVER_MSG("step 1");
-
- if (net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- DEBUG_SERVER_MSG("bind server socket with service acess point = [0x%x]", SNEP_SAP);
- if (net_nfc_controller_llcp_bind(state->socket, SNEP_SAP, result) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- DEBUG_SERVER_MSG("listen server socket with service access name = [%s]", SNEP_SAN);
- state->step = NET_NFC_LLCP_STEP_02;
- if (net_nfc_controller_llcp_listen(state->handle, (uint8_t *)SNEP_SAN, state->socket, result, state) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->type_app_protocol = NET_NFC_SNEP;
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- DEBUG_SERVER_MSG("step 2");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep: listen is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- net_nfc_llcp_state_t * new_client = NULL;
- _net_nfc_util_alloc_mem(new_client, sizeof (net_nfc_llcp_state_t));
-
- new_client->handle = state->handle;
- new_client->state = state->state;
- new_client->socket = state->incomming_socket;
- new_client->step = NET_NFC_LLCP_STEP_03;
- new_client->user_data = NULL;
-
- memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER);
- snep_server_data.length = SNEP_MAX_BUFFER;
-
- current_llcp_server_state.handle = state->handle;
- current_llcp_server_state.socket = state->incomming_socket;
-
- net_nfc_service_llcp_add_state(new_client);
-
- if (net_nfc_controller_llcp_recv(new_client->handle, new_client->socket, &snep_server_data, result, new_client) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- {
- DEBUG_SERVER_MSG("step 3");
- DEBUG_SERVER_MSG("receive request msg from snep client");
-
- state->step = NET_NFC_LLCP_STEP_04;
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep : recevie is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- uint8_t resp_code = 0;
- data_s* resp_msg = NULL;
-
- if (_net_nfc_service_llcp_snep_check_req_msg(&snep_server_data, &resp_code) != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("Not valid request msg = [0x%X]", resp_code);
- resp_msg = _net_nfc_service_llcp_snep_create_msg(resp_code, NULL);
-
- if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)
- {
- _net_nfc_util_free_mem(resp_msg->buffer);
- _net_nfc_util_free_mem(resp_msg);
- }
- }
- else
- {
- uint32_t information_length = 0;
- if (_net_nfc_service_llcp_snep_get_information_length(&snep_server_data, &information_length) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("MAX capa of server is = [%d] and received byte is = [%d]", SNEP_MAX_BUFFER, snep_server_data.length);
-
- /* msg = header(fixed 6 byte) + information(changable) */
- if (information_length + 6 > SNEP_MAX_BUFFER)
- {
- DEBUG_SERVER_MSG("request msg length is too long to receive at a time");
- DEBUG_SERVER_MSG("total msg length is = [%d]", information_length + 6);
-
- data_s* fragment = NULL;
-
- _net_nfc_util_alloc_mem(fragment, sizeof(data_s));
- if (fragment == NULL)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- _net_nfc_util_alloc_mem(fragment->buffer, (information_length + 6) * sizeof(uint8_t));
- if (fragment->buffer == NULL)
- {
- state->step = NET_NFC_STATE_ERROR;
- _net_nfc_util_free_mem(fragment);
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_05;
-
- fragment->length = information_length + 6;
- state->payload = fragment;
-
- memcpy(fragment->buffer, snep_server_data.buffer, snep_server_data.length);
-
- /* set zero. this is first time */
- state->fragment_offset = 0;
- state->fragment_offset += snep_server_data.length;
-
- resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_CONT, NULL);
-
- DEBUG_SERVER_MSG("send continue response msg");
-
- if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)
- {
- _net_nfc_util_free_mem(resp_msg->buffer);
- _net_nfc_util_free_mem(resp_msg);
- }
- }
- else
- {
- resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL);
-
- DEBUG_SERVER_MSG("send success response msg");
-
- if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)
- {
- _net_nfc_util_free_mem(resp_msg->buffer);
- _net_nfc_util_free_mem(resp_msg);
- }
-
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- data_s temp = { NULL, 0 };
-
- /* version, command, information_length are head. */
- temp.buffer = snep_server_data.buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t);
- if ((_net_nfc_service_llcp_snep_get_information_length(&snep_server_data, &(temp.length))) == NET_NFC_OK)
- {
- net_nfc_response_p2p_receive_t resp = { 0 };
- data_s data;
-
- DEBUG_SERVER_MSG("process received msg");
-
- _net_nfc_util_alloc_mem(data.buffer, temp.length);
-
- memcpy(data.buffer, temp.buffer, temp.length);
-
- resp.data.length = temp.length;
- resp.result = NET_NFC_OK;
-
- net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof(net_nfc_response_p2p_receive_t),
- data.buffer, resp.data.length, NULL);
-
- net_nfc_service_msg_processing(&temp);
- }
- }
- }
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- {
- DEBUG_SERVER_MSG("step 4");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep : sending is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- else
- {
- net_nfc_error_e error;
-
- DEBUG_SERVER_MSG("snep : sending response is success...");
- state->step = NET_NFC_LLCP_STEP_02;
- state->handle = current_llcp_server_state.handle;
- state->incomming_socket = current_llcp_server_state.socket;
-
- _net_nfc_service_llcp_snep_server(state, &error);
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_05 :
- {
- DEBUG_SERVER_MSG("step 5");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep: sending CONT response is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_06;
-
- memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER);
- snep_server_data.length = SNEP_MAX_BUFFER;
-
- if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_server_data, result, state) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_06 :
- {
- DEBUG_SERVER_MSG("step 6");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep: recv is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- if (((data_s*)state->payload)->length > (snep_server_data.length + state->fragment_offset))
- {
- /* receive more */
- /* copy fragment to buffer. */
- data_s* fragment = state->payload;
- if (fragment != NULL)
- {
- memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length);
- state->fragment_offset += snep_server_data.length;
- }
-
- state->step = NET_NFC_LLCP_STEP_06;
-
- memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER);
- snep_server_data.length = SNEP_MAX_BUFFER;
-
- if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_server_data, result, state) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- else if (((data_s*)state->payload)->length == (snep_server_data.length + state->fragment_offset))
- {
- /* receving is completed */
- DEBUG_SERVER_MSG("recv is completed");
-
- data_s* fragment = state->payload;
-
- if (fragment != NULL)
- {
- memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length);
- state->fragment_offset += snep_server_data.length;
- }
-
- data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL);
-
- if (resp_msg != NULL)
- {
- if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)
- {
-
- _net_nfc_util_free_mem(resp_msg->buffer);
- _net_nfc_util_free_mem(resp_msg);
- }
- }
-
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- data_s temp = { NULL, 0 };
-
- /* version, command, information_length are head. */
- temp.buffer = ((data_s*)(state->payload))->buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t);
- if ((_net_nfc_service_llcp_snep_get_information_length(((data_s*)(state->payload)), &(temp.length))) == NET_NFC_OK)
- {
- net_nfc_response_p2p_receive_t resp = { 0 };
- data_s data;
-
- _net_nfc_util_alloc_mem(data.buffer, temp.length);
-
- memcpy(data.buffer, temp.buffer, temp.length);
-
- resp.data.length = temp.length;
- resp.result = NET_NFC_OK;
-
- net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof(net_nfc_response_p2p_receive_t),
- data.buffer, resp.data.length, NULL);
-
- net_nfc_service_msg_processing(&temp);
- }
-
- _net_nfc_util_free_mem(((data_s*)(state->payload))->buffer);
- _net_nfc_util_free_mem(state->payload);
- state->payload = NULL;
- state->step = 0;
- }
- else
- {
- DEBUG_SERVER_MSG("msg length is not matched. we have got more message");
-
- data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_BAD_REQ, NULL);
-
- if (resp_msg != NULL)
- {
- if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)
- {
-
- _net_nfc_util_free_mem(resp_msg->buffer);
- _net_nfc_util_free_mem(resp_msg);
- }
- }
- _net_nfc_util_free_mem(((data_s*)(state->payload))->buffer);
- _net_nfc_util_free_mem(state->payload);
- state->payload = NULL;
- state->step = 0;
- }
- }
- break;
-
- case NET_NFC_STATE_SOCKET_ERROR :
- {
- DEBUG_SERVER_MSG("snep : socket error is received %d", state->prev_result);
- need_clean_up = true;
- }
- break;
-
- default :
- {
- DEBUG_SERVER_MSG("unknown step = [%d]", state->step);
- need_clean_up = true;
- }
- break;
-
- }
-
- if (state->step == NET_NFC_STATE_ERROR)
- {
- net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR);
- DEBUG_SERVER_MSG("nfc state error");
- state->step = 0;
- }
-
- if (need_clean_up == true)
- {
- DEBUG_SERVER_MSG("socket close :: snep server");
-
- net_nfc_server_unset_server_state(NET_NFC_SNEP_SERVER_CONNECTED);
-
- net_nfc_controller_llcp_socket_close(state->socket, result);
- net_nfc_service_llcp_remove_state(state);
- _net_nfc_util_free_mem(state);
- }
-
- if (*result != NET_NFC_OK)
- {
- return false;
- }
- return true;
-}
-
-static bool _net_nfc_service_llcp_npp_server(net_nfc_llcp_state_t * state, net_nfc_error_e* result)
-{
- bool need_clean_up = false;
-
- DEBUG_SERVER_MSG("_net_nfc_service_llcp_npp_server");
-
- if (result == NULL)
- {
- DEBUG_SERVER_MSG("result is NULL");
- return false;
- }
- *result = NET_NFC_OK;
-
- switch (state->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- {
- DEBUG_SERVER_MSG("NPP step 1");
-
- if (net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false)
- {
- DEBUG_SERVER_MSG("creaete socket for npp FAIL");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- if (net_nfc_controller_llcp_bind(state->socket, NPP_SAP, result) == false)
- {
- DEBUG_SERVER_MSG("bind socket for npp FAIL");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_02;
- if (net_nfc_controller_llcp_listen(state->handle, (uint8_t *)NPP_SAN, state->socket, result, state) == false)
- {
- DEBUG_SERVER_MSG("listen socket for npp FAIL");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- state->type_app_protocol = NET_NFC_NPP;
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- DEBUG_SERVER_MSG("step 2");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("NPP: listen is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- net_nfc_llcp_state_t * new_client = NULL;
- _net_nfc_util_alloc_mem(new_client, sizeof (net_nfc_llcp_state_t));
-
- new_client->handle = state->handle;
- new_client->state = state->state;
- new_client->socket = state->incomming_socket;
- new_client->step = NET_NFC_LLCP_STEP_03;
- new_client->user_data = NULL;
-
- memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER);
- snep_server_data.length = SNEP_MAX_BUFFER;
-
- current_llcp_server_state.handle = state->handle;
- current_llcp_server_state.socket = state->incomming_socket;
- net_nfc_service_llcp_add_state(new_client);
-
- if (net_nfc_controller_llcp_recv(new_client->handle, new_client->socket, &snep_server_data, result, new_client) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- {
- /* send back success response */
- DEBUG_SERVER_MSG("step 3");
- DEBUG_SERVER_MSG("receive request msg from snep client");
-
- state->step = NET_NFC_LLCP_STEP_04;
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep : recevie is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- uint8_t resp_code = 0;
- data_s* resp_msg = NULL;
-
- if (_net_nfc_service_llcp_npp_check_req_msg(&snep_server_data, &resp_code) != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("Not valid request msg = [0x%X]", resp_code);
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- else
- {
- uint32_t information_length = 0;
- if (_net_nfc_service_llcp_npp_get_information_length(&snep_server_data, &information_length) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("MAX capa of server is = [%d] and received byte is = [%d]", SNEP_MAX_BUFFER, snep_server_data.length);
-
- /* msg = header(fixed 10 byte) + information(changable) */
- if (information_length + 10 > SNEP_MAX_BUFFER)
- {
- DEBUG_SERVER_MSG("request msg length is too long to receive at a time");
-
- DEBUG_SERVER_MSG("total msg length is = [%d]", information_length + 10);
-
- data_s* fragment = NULL;
-
- _net_nfc_util_alloc_mem(fragment, sizeof(data_s));
- if (fragment == NULL)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- _net_nfc_util_alloc_mem(fragment->buffer, (information_length + 10) * sizeof(uint8_t));
- if (fragment->buffer == NULL)
- {
- state->step = NET_NFC_STATE_ERROR;
- _net_nfc_util_free_mem(fragment);
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_05;
-
- fragment->length = information_length + 10;
- state->payload = fragment;
-
- memcpy(fragment->buffer, snep_server_data.buffer, snep_server_data.length);
-
- /* set zero. this is first time */
- state->fragment_offset = 0;
- state->fragment_offset += snep_server_data.length;
-
- resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_CONT, NULL);
-
- DEBUG_SERVER_MSG("send continue response msg");
-
- if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)
- {
-
- _net_nfc_util_free_mem(resp_msg->buffer);
- _net_nfc_util_free_mem(resp_msg);
- }
- }
- else /*the size of the ndef is smaller than the max size*/
- {
- DEBUG_SERVER_MSG("Success to receive the msg");
-
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- data_s temp = { NULL, 0 };
-
- /* version, command, information_length are head. */
- temp.buffer = snep_server_data.buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + sizeof(uint32_t);
- DEBUG_SERVER_MSG("check the string = [%s]", temp.buffer);
- if ((_net_nfc_service_llcp_npp_get_information_length(&snep_server_data, &(temp.length))) == NET_NFC_OK)
- {
- net_nfc_response_p2p_receive_t resp = { 0 };
- data_s data;
-
- DEBUG_SERVER_MSG("process received msg");
-
- _net_nfc_util_alloc_mem(data.buffer, temp.length);
-
- memcpy(data.buffer, temp.buffer, temp.length);
-
- resp.data.length = temp.length;
- resp.result = NET_NFC_OK;
-
- net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof(net_nfc_response_p2p_receive_t),
- data.buffer, resp.data.length, NULL);
-
- net_nfc_service_msg_processing(&temp);
- }
- }
- }
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- {
- DEBUG_SERVER_MSG("step 4");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("NPP : sending is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- else
- {
- net_nfc_error_e error;
-
- DEBUG_SERVER_MSG("NPP : Receiving the message is success...");
- state->step = NET_NFC_LLCP_STEP_02;
- state->handle = current_llcp_server_state.handle;
- state->incomming_socket = current_llcp_server_state.socket;
- _net_nfc_service_llcp_npp_server(state, &error);
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_05 :
- {
- DEBUG_SERVER_MSG("step 5");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("NPP: sending CONT response is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_06;
-
- memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER);
- snep_server_data.length = SNEP_MAX_BUFFER;
-
- if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_server_data, result, state) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_06 :
- {
- DEBUG_SERVER_MSG("step 6");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep: recv is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- if (((data_s*)state->payload)->length > (snep_server_data.length + state->fragment_offset))
- {
- /* receive more */
- /* copy fragment to buffer. */
- data_s* fragment = state->payload;
- if (fragment != NULL)
- {
- memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length);
- state->fragment_offset += snep_server_data.length;
- }
-
- state->step = NET_NFC_LLCP_STEP_06;
-
- memset(snep_server_data.buffer, 0x00, SNEP_MAX_BUFFER);
- snep_server_data.length = SNEP_MAX_BUFFER;
-
- if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_server_data, result, state) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- else if (((data_s*)state->payload)->length == (snep_server_data.length + state->fragment_offset))
- {
- /* receving is completed */
- DEBUG_SERVER_MSG("recv is completed");
- data_s* fragment = state->payload;
- if (fragment != NULL)
- {
- memcpy(fragment->buffer + state->fragment_offset, snep_server_data.buffer, snep_server_data.length);
- state->fragment_offset += snep_server_data.length;
- }
-
- data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_SUCCESS, NULL);
-
- if (resp_msg != NULL)
- {
- if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)
- {
- _net_nfc_util_free_mem(resp_msg->buffer);
- _net_nfc_util_free_mem(resp_msg);
- }
- }
-
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- data_s temp = { NULL, 0 };
-
- /* version, command, information_length are head. */
- temp.buffer = ((data_s*)(state->payload))->buffer + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t);
- if ((_net_nfc_service_llcp_snep_get_information_length(((data_s*)(state->payload)), &(temp.length))) == NET_NFC_OK)
- {
- net_nfc_response_p2p_receive_t resp = { 0 };
- data_s data;
-
- _net_nfc_util_alloc_mem(data.buffer, temp.length);
-
- memcpy(data.buffer, temp.buffer, temp.length);
-
- resp.data.length = temp.length;
- resp.result = NET_NFC_OK;
-
- net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_P2P_RECEIVE, (void*)&resp, sizeof(net_nfc_response_p2p_receive_t),
- data.buffer, resp.data.length, NULL);
-
- net_nfc_service_msg_processing(&temp);
- }
-
- _net_nfc_util_free_mem(((data_s*)(state->payload))->buffer);
- _net_nfc_util_free_mem(state->payload);
- state->payload = NULL;
- state->step = 0;
- }
- else
- {
- DEBUG_SERVER_MSG("msg length is not matched. we have got more message");
-
- data_s* resp_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_RESP_BAD_REQ, NULL);
-
- if (resp_msg != NULL)
- {
- if (net_nfc_controller_llcp_send(state->handle, state->socket, resp_msg, result, state) == false)
- {
- _net_nfc_util_free_mem(resp_msg->buffer);
- _net_nfc_util_free_mem(resp_msg);
- }
- }
-
- _net_nfc_util_free_mem(((data_s*)(state->payload))->buffer);
- _net_nfc_util_free_mem(state->payload);
- state->payload = NULL;
- state->step = 0;
- }
-
- net_nfc_error_e error;
-
- state->step = NET_NFC_LLCP_STEP_02;
- state->handle = current_llcp_server_state.handle;
- state->incomming_socket = current_llcp_server_state.socket;
- _net_nfc_service_llcp_npp_server(state, &error);
- }
- break;
-
- case NET_NFC_STATE_SOCKET_ERROR :
- {
- DEBUG_SERVER_MSG("snep : socket error is received %d", state->prev_result);
- need_clean_up = true;
- }
- break;
-
- default :
- {
- DEBUG_SERVER_MSG("unknown step = [%d]", state->step);
- need_clean_up = true;
- }
- break;
- }
-
- if (state->step == NET_NFC_STATE_ERROR)
- {
- /* server should not notify exchanger result to client application. it MUST be handled in nfc-manager side */
- net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR);
- DEBUG_SERVER_MSG("nfc state error");
- state->step = 0;
- }
-
- if (need_clean_up == true)
- {
- DEBUG_SERVER_MSG("socket close :: NPP server");
-
- net_nfc_server_unset_server_state(NET_NFC_NPP_SERVER_CONNECTED);
-
- net_nfc_controller_llcp_socket_close(state->socket, result);
- net_nfc_service_llcp_remove_state(state);
- _net_nfc_util_free_mem(state);
- }
-
- if (*result != NET_NFC_OK)
- {
- return false;
- }
- return true;
-}
-
-static bool _net_nfc_service_llcp_client(net_nfc_llcp_state_t * state, net_nfc_error_e* result)
-{
- bool need_clean_up = false;
-
- DEBUG_SERVER_MSG("_net_nfc_service_llcp_client [%d]", state->step);
-
- if (result == NULL)
- {
- DEBUG_SERVER_MSG("result is NULL");
- return false;
- }
-
- *result = NET_NFC_OK;
-
- if (((net_nfc_server_get_server_state() & NET_NFC_SNEP_CLIENT_CONNECTED) || (net_nfc_server_get_server_state() & NET_NFC_NPP_CLIENT_CONNECTED))
- && state->step == NET_NFC_LLCP_STEP_01)
- {
- state->socket = current_llcp_client_state.socket;
- state->type_app_protocol = current_llcp_client_state.type_app_protocol;
- state->step = NET_NFC_LLCP_STEP_02;
- }
-
- switch (state->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- {
- DEBUG_SERVER_MSG("step 1");
-
- if (net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, SNEP_MAX_BUFFER, 1, result, state) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_SERVER_MSG(" Fail to Create socket for SNEP in client.");
- break;
- }
-
- DEBUG_SERVER_MSG("connect to remote server with socket = [0x%x]", state->socket);
-
- state->step = NET_NFC_LLCP_STEP_02;
-
- if (net_nfc_controller_llcp_connect_by_url(state->handle, state->socket, (uint8_t *)SNEP_SAN, result, state) == true)
- {
- DEBUG_SERVER_MSG("Success to connect by url for SNEP in client.");
- net_nfc_server_set_server_state(NET_NFC_SNEP_CLIENT_CONNECTED);
- state->type_app_protocol = NET_NFC_SNEP;
- break;
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_SERVER_MSG("Fail to connect to socket for snep & npp in client.");
- break;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- DEBUG_SERVER_MSG("step 2");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep client: connect is failed [%d]", state->prev_result);
-
- if (NET_NFC_OPERATION_FAIL == state->prev_result)
- {
- if (net_nfc_controller_llcp_connect_by_url(state->handle, state->socket, (uint8_t *)"com.android.npp", result, state) == true)
- {
- DEBUG_SERVER_MSG("Success to connect by url for NPP in client.");
- state->type_app_protocol = NET_NFC_NPP;
- state->step = NET_NFC_LLCP_STEP_02;
- net_nfc_server_set_server_state(NET_NFC_NPP_CLIENT_CONNECTED);
-
- break;
- }
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- }
- break;
- }
-
- if (state->payload == NULL)
- {
- DEBUG_SERVER_MSG("no data to send to server. just terminate client thread");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- net_nfc_llcp_socket_option_s retmoe_socket_info = { 0, 0, 0 };
- if (net_nfc_controller_llcp_get_remote_socket_info(state->handle, state->socket, &retmoe_socket_info, result) == true)
- {
- state->max_capability = retmoe_socket_info.miu;
- DEBUG_SERVER_MSG("SERVER MIU = [%d]", state->max_capability);
- }
- else
- {
- state->max_capability = SNEP_MAX_BUFFER;
- DEBUG_SERVER_MSG("SERVER MIU = [%d]", state->max_capability);
- }
-
- data_s* req_msg = NULL;
-
- if (state->type_app_protocol == NET_NFC_SNEP)
- {
- req_msg = _net_nfc_service_llcp_snep_create_msg(SNEP_REQ_PUT, (data_s *)state->payload);
- }
- else
- {
- req_msg = _net_nfc_service_llcp_npp_create_msg((data_s *)state->payload);
- }
-
- _net_nfc_util_free_mem(((data_s *)state->payload)->buffer);
- _net_nfc_util_free_mem(state->payload);
-
- state->payload = NULL;
-
- if (req_msg == NULL)
- {
- DEBUG_SERVER_MSG("failed to create req msg");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_03;
-
- if (req_msg->length <= state->max_capability)
- {
- DEBUG_SERVER_MSG("send req data");
-
- if (net_nfc_controller_llcp_send(state->handle, state->socket, req_msg, result, state) == false)
- {
- DEBUG_SERVER_MSG("failed to send req msg");
- _net_nfc_util_free_mem(req_msg->buffer);
- _net_nfc_util_free_mem(req_msg);
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- else
- {
- _net_nfc_util_free_mem(req_msg->buffer);
- _net_nfc_util_free_mem(req_msg);
- }
- }
- else
- {
- /* send first fragment */
- DEBUG_SERVER_MSG("send first fragment");
-
- data_s fragment = { NULL, 0 };
-
- _net_nfc_util_alloc_mem(fragment.buffer, state->max_capability * sizeof(uint8_t));
- if (fragment.buffer == NULL)
- {
- _net_nfc_util_free_mem(req_msg->buffer);
- _net_nfc_util_free_mem(req_msg);
- state->payload = NULL;
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- memcpy(fragment.buffer, req_msg->buffer, state->max_capability);
- fragment.length = state->max_capability;
-
- data_s* extra_msg = NULL;
-
- _net_nfc_util_alloc_mem(extra_msg, sizeof(data_s));
- if (extra_msg == NULL)
- {
- _net_nfc_util_free_mem(req_msg->buffer);
- _net_nfc_util_free_mem(req_msg);
- _net_nfc_util_free_mem(fragment.buffer);
- state->payload = NULL;
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- _net_nfc_util_alloc_mem(extra_msg->buffer, (req_msg->length - state->max_capability) * sizeof(uint8_t));
- if (extra_msg->buffer == NULL)
- {
- _net_nfc_util_free_mem(req_msg->buffer);
- _net_nfc_util_free_mem(req_msg);
- _net_nfc_util_free_mem(extra_msg);
- _net_nfc_util_free_mem(fragment.buffer);
- state->payload = NULL;
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- extra_msg->length = req_msg->length - state->max_capability;
- memcpy(extra_msg->buffer, req_msg->buffer + state->max_capability, extra_msg->length);
-
- state->payload = extra_msg;
-
- net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state);
-
- _net_nfc_util_free_mem(req_msg->buffer);
- _net_nfc_util_free_mem(req_msg);
- _net_nfc_util_free_mem(fragment.buffer);
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- {
- DEBUG_SERVER_MSG("step 3");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result);
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_04;
-
- if (state->type_app_protocol == NET_NFC_SNEP)
- {
- memset(snep_client_data.buffer, 0x00, SNEP_MAX_BUFFER);
- snep_client_data.length = SNEP_MAX_BUFFER;
-
- DEBUG_SERVER_MSG("try to recv server response");
-
- if (net_nfc_controller_llcp_recv(state->handle, state->socket, &snep_client_data, result, state) == false)
- {
- DEBUG_SERVER_MSG("recv operation is failed");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- else
- {
- DEBUG_SERVER_MSG("NET_NFC_NPP. Don't use the response message. So we skip it!");
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- {
- DEBUG_SERVER_MSG("step 4");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep client: llcp recv is failed [%d]", state->prev_result);
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- if (state->type_app_protocol == NET_NFC_NPP)
- {
- net_nfc_response_p2p_send_t req_msg = { 0, };
-
- DEBUG_SERVER_MSG("It's NET_NFC_NPP. Send completed event to client!");
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- req_msg.handle = state->handle;
- req_msg.result = NET_NFC_OK;
- req_msg.trans_param = state->user_data;
-
- net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL);
- break;
- }
-
- uint8_t code = 0;
-
- if (_net_nfc_service_llcp_snep_check_resp_msg(&snep_client_data) == NET_NFC_OK)
- {
- if (_net_nfc_service_llcp_snep_get_code(&snep_client_data, &code) == NET_NFC_OK)
- {
- if (code == SNEP_RESP_SUCCESS)
- {
- DEBUG_SERVER_MSG("success response");
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- net_nfc_response_p2p_send_t req_msg = { 0, };
-
- req_msg.handle = state->handle;
- req_msg.result = NET_NFC_OK;
- req_msg.trans_param = state->user_data;
-
- net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL);
- }
- else if (code == SNEP_RESP_CONT)
- {
- DEBUG_SERVER_MSG("continue response");
-
- data_s* msg = state->payload;
-
- if (msg == NULL)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- if (msg->length > state->max_capability)
- {
- state->step = NET_NFC_LLCP_STEP_05;
-
- data_s fragment = { NULL, 0 };
- data_s* extra_msg = NULL;
-
- _net_nfc_util_alloc_mem(fragment.buffer, state->max_capability * sizeof(uint8_t));
- if (fragment.buffer == NULL)
- {
- _net_nfc_util_free_mem(msg->buffer);
- _net_nfc_util_free_mem(msg);
- state->payload = NULL;
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- fragment.length = state->max_capability;
- memcpy(fragment.buffer, msg->buffer, state->max_capability);
-
- _net_nfc_util_alloc_mem(extra_msg, sizeof(data_s));
- if (extra_msg == NULL)
- {
- _net_nfc_util_free_mem(fragment.buffer);
- _net_nfc_util_free_mem(msg->buffer);
- _net_nfc_util_free_mem(msg);
- state->step = NET_NFC_STATE_ERROR;
- state->payload = NULL;
- break;
- }
-
- _net_nfc_util_alloc_mem(extra_msg->buffer, (msg->length - state->max_capability) * sizeof(uint8_t));
- if (extra_msg->buffer == NULL)
- {
- _net_nfc_util_free_mem(extra_msg);
- _net_nfc_util_free_mem(fragment.buffer);
- _net_nfc_util_free_mem(msg->buffer);
- _net_nfc_util_free_mem(msg);
- state->step = NET_NFC_STATE_ERROR;
- state->payload = NULL;
- break;
- }
-
- extra_msg->length = msg->length - state->max_capability;
- memcpy(extra_msg->buffer, msg->buffer + state->max_capability, msg->length - state->max_capability);
-
- state->payload = extra_msg;
-
- DEBUG_SERVER_MSG("send next fragment msg");
- net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state);
-
- _net_nfc_util_free_mem(fragment.buffer);
- _net_nfc_util_free_mem(msg->buffer);
- _net_nfc_util_free_mem(msg);
- }
- else
- {
- DEBUG_SERVER_MSG("send last fragment msg");
-
- state->step = NET_NFC_LLCP_STEP_06;
-
- net_nfc_controller_llcp_send(state->handle, state->socket, msg, result, state);
-
- _net_nfc_util_free_mem(msg->buffer);
- _net_nfc_util_free_mem(msg);
-
- state->payload = NULL;
- }
- }
- else
- {
- DEBUG_SERVER_MSG("error response = [%d] from server", code);
- }
- }
- }
- else
- {
- DEBUG_SERVER_MSG("we have got error response");
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_05 :
- {
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result);
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- /* check extra data */
- if (state->payload == NULL)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- data_s* msg = state->payload;
-
- if (msg->length > state->max_capability)
- {
- state->step = NET_NFC_LLCP_STEP_05;
-
- data_s fragment = { NULL, 0 };
- data_s* extra_msg = NULL;
-
- _net_nfc_util_alloc_mem(fragment.buffer, state->max_capability * sizeof(uint8_t));
- fragment.length = state->max_capability;
- memcpy(fragment.buffer, msg->buffer, state->max_capability);
-
- _net_nfc_util_alloc_mem(extra_msg, sizeof(data_s));
-
- _net_nfc_util_alloc_mem(extra_msg->buffer, (msg->length - state->max_capability) * sizeof(uint8_t));
- extra_msg->length = msg->length - state->max_capability;
- memcpy(extra_msg->buffer, msg->buffer + state->max_capability, msg->length - state->max_capability);
-
- state->payload = extra_msg;
-
- DEBUG_SERVER_MSG("send next fragment msg");
- net_nfc_controller_llcp_send(state->handle, state->socket, &fragment, result, state);
-
- _net_nfc_util_free_mem(fragment.buffer);
- _net_nfc_util_free_mem(msg->buffer);
- _net_nfc_util_free_mem(msg);
- }
- else
- {
- state->step = NET_NFC_LLCP_STEP_06;
-
- DEBUG_SERVER_MSG("send last fragment msg");
-
- net_nfc_controller_llcp_send(state->handle, state->socket, msg, result, state);
-
- _net_nfc_util_free_mem(msg->buffer);
- _net_nfc_util_free_mem(msg);
-
- state->payload = NULL;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_06 :
- {
- net_nfc_response_p2p_send_t req_msg = { 0, };
-
- req_msg.handle = state->handle;
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("snep client: llcp send is failed [%d]", state->prev_result);
-
- req_msg.result = NET_NFC_P2P_SEND_FAIL;
- req_msg.trans_param = state->user_data;
-
- net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL);
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- else
- {
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- req_msg.result = NET_NFC_OK;
- req_msg.trans_param = state->user_data;
-
- net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL);
- }
-
- DEBUG_SERVER_MSG("sending last fragment msg is ok");
- }
- break;
-
- case NET_NFC_STATE_SOCKET_ERROR :
- {
- DEBUG_SERVER_MSG("snep client: socket error is received [%d]", state->prev_result);
- need_clean_up = true;
- }
- break;
-
- default :
- need_clean_up = true;
- break;
- }
-
- if (state->step == NET_NFC_STATE_ERROR)
- {
- net_nfc_response_p2p_send_t req_msg = { 0, };
-
- req_msg.handle = state->handle;
- req_msg.result = NET_NFC_P2P_SEND_FAIL;
- req_msg.trans_param = state->user_data;
-
- net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR);
- net_nfc_send_response_msg(state->client_fd, NET_NFC_MESSAGE_P2P_SEND, &req_msg, sizeof(net_nfc_response_p2p_send_t), NULL);
-
- net_nfc_server_unset_server_state(NET_NFC_SNEP_CLIENT_CONNECTED | NET_NFC_NPP_CLIENT_CONNECTED);
-
- need_clean_up = true;
- }
-
- if (need_clean_up == true)
- {
- DEBUG_SERVER_MSG("socket close :: LLCP client");
-
- net_nfc_controller_llcp_socket_close(state->socket, result);
- net_nfc_service_llcp_remove_state(state);
- _net_nfc_util_free_mem(state);
-
- net_nfc_server_unset_server_state(NET_NFC_SNEP_CLIENT_CONNECTED | NET_NFC_NPP_CLIENT_CONNECTED);
- }
-
- if (*result != NET_NFC_OK && *result != NET_NFC_BUSY)
- {
- DEBUG_SERVER_MSG("error = [%d]", *result);
- return false;
- }
-
- return true;
-}
-
-static data_s* _net_nfc_service_llcp_snep_create_msg(snep_command_field_e resp_field, data_s* information)
-{
- uint8_t response = (uint8_t)resp_field;
- uint8_t version = 0;
- uint32_t length_field = 0;
-
- version = SNEP_MAJOR_VER;
- version = (((version << 4) & 0xf0) | (SNEP_MINOR_VER & 0x0f));
-
- data_s* snep_msg = NULL;
-
- if (information == NULL)
- {
- length_field = 0;
-
- _net_nfc_util_alloc_mem(snep_msg, sizeof(data_s));
- if (snep_msg == NULL)
- {
- return NULL;
- }
-
- snep_msg->length = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t);
- _net_nfc_util_alloc_mem(snep_msg->buffer, snep_msg->length * sizeof(uint8_t));
- if (snep_msg->buffer == NULL)
- {
-
- _net_nfc_util_free_mem(snep_msg);
- return NULL;
- }
-
- uint8_t* temp = snep_msg->buffer;
-
- /* copy version */
- *temp = version;
- temp++;
-
- /* copy response */
- *temp = response;
- temp++;
- }
- else
- {
- _net_nfc_util_alloc_mem(snep_msg, sizeof(data_s));
- if (snep_msg == NULL)
- {
- return NULL;
- }
- /* version response length payload*/
- snep_msg->length = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + information->length;
-
- _net_nfc_util_alloc_mem(snep_msg->buffer, snep_msg->length * sizeof(uint8_t));
- if (snep_msg->buffer == NULL)
- {
- _net_nfc_util_free_mem(snep_msg);
- return NULL;
- }
-
- memset(snep_msg->buffer, 0x00, snep_msg->length);
-
- uint8_t* temp = snep_msg->buffer;
-
- /* copy version */
- *temp = version;
- temp++;
-
- /* copy response */
- *temp = response;
- temp++;
-
- DEBUG_SERVER_MSG("information->length[%d]", information->length);
- /* change the length data as network order for compatibility with android */
- length_field = htonl(information->length);
-
- /* length will be se 0. so we don't need to copy value */
- memcpy(temp, &length_field, sizeof(uint32_t));
- temp += sizeof(uint32_t);
-
- /* copy ndef information to response msg */
- memcpy(temp, information->buffer, information->length);
- }
- return snep_msg;
-}
-
-static data_s* _net_nfc_service_llcp_npp_create_msg(data_s* information)
-{
- uint8_t version;
- uint32_t length_field = 0;
- uint32_t npp_ndef_entry = NPP_NDEF_ENTRY;
- uint32_t big_endian_npp_ndef_entry = 0;
-
- version = NPP_MAJOR_VER;
- version = (((version << 4) & 0xf0) | (NPP_MINOR_VER & 0x0f));
-
- data_s* npp_msg = NULL;
-
- if (information == NULL)
- {
- length_field = 0;
-
- _net_nfc_util_alloc_mem(npp_msg, sizeof(data_s));
- if (npp_msg == NULL)
- {
- return NULL;
- }
- /* version ndef entry action code message length*/
- npp_msg->length = sizeof(uint8_t) + sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t);
- _net_nfc_util_alloc_mem(npp_msg->buffer, npp_msg->length * sizeof(uint8_t));
- if (npp_msg->buffer == NULL)
- {
-
- _net_nfc_util_free_mem(npp_msg);
- return NULL;
- }
-
- uint8_t* temp = npp_msg->buffer;
-
- /* copy version */
- *temp = version;
- temp++;
-
- /* copy npp ndef entry */
- big_endian_npp_ndef_entry = htonl(npp_ndef_entry);
- memcpy((void *)temp, (void *)&big_endian_npp_ndef_entry, sizeof(uint32_t));
- temp += sizeof(uint32_t);
- }
- else
- {
-
- /*Make the npp header*/
- net_nfc_llcp_npp_t npp_header_buffer;
-
- npp_header_buffer.npp_version = version;
- npp_header_buffer.npp_ndef_entry = htonl(NPP_NDEF_ENTRY);
- npp_header_buffer.npp_action_code = NPP_ACTION_CODE;
- npp_header_buffer.npp_ndef_length = htonl(information->length);
-
- /*Make the npp message*/
- _net_nfc_util_alloc_mem(npp_msg, sizeof(data_s));
- if (npp_msg == NULL)
- {
- return NULL;
- }
-
- npp_msg->length = sizeof(net_nfc_llcp_npp_t) + information->length;
-
- _net_nfc_util_alloc_mem(npp_msg->buffer, npp_msg->length * sizeof(uint8_t));
- if (npp_msg->buffer == NULL)
- {
- _net_nfc_util_free_mem(npp_msg);
- return NULL;
- }
-
- memset(npp_msg->buffer, 0x00, npp_msg->length);
-
- memcpy(npp_msg->buffer, &npp_header_buffer, sizeof(net_nfc_llcp_npp_t));
-
- memcpy((npp_msg->buffer) + sizeof(net_nfc_llcp_npp_t), information->buffer, information->length);
-
- }
-
- return npp_msg;
-}
-
-static net_nfc_error_e _net_nfc_service_llcp_snep_check_req_msg(data_s* snep_msg, uint8_t* resp_code)
-{
- /* version check */
- /* command check */
-
- if (snep_msg == NULL || snep_msg->buffer == NULL || resp_code == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- *resp_code = 0;
-
- uint8_t* temp = NULL;
- uint8_t version = 0;
- bool is_supported_req = false;
- uint8_t req = 0;
-
- temp = snep_msg->buffer;
-
- /* get vesrion. and compare it with ours */
- version = *temp;
-
- if (version == 0)
- {
- DEBUG_SERVER_MSG("no version is set");
- *resp_code = SNEP_RESP_UNSUPPORTED_VER;
- return NET_NFC_UNKNOWN_ERROR;
- }
- else
- {
- uint8_t major = (version & 0xf0) >> 4;
- uint8_t minor = (version & 0x0f);
-
- DEBUG_SERVER_MSG("major = [%d], minor = [%d]", major, minor);
-
- if (major != SNEP_MAJOR_VER || minor > SNEP_MINOR_VER)
- {
- DEBUG_SERVER_MSG("version is not matched");
- *resp_code = SNEP_RESP_UNSUPPORTED_VER;
- return NET_NFC_UNKNOWN_ERROR;
- }
- }
-
- temp++;
-
- /* get command */
- req = *temp;
- temp++;
-
- switch (req)
- {
- case SNEP_REQ_CONTINUE :
- case SNEP_REQ_PUT :
- case SNEP_REQ_REJECT :
- is_supported_req = true;
- break;
-
- case SNEP_REQ_GET :
- default :
- is_supported_req = false;
- break;
-
- }
-
- if (is_supported_req == false)
- {
-
- DEBUG_SERVER_MSG("not supported req command");
- *resp_code = SNEP_RESP_NOT_IMPLEMENT;
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- uint32_t information_length = 0;
-
- memcpy(&information_length, temp, sizeof(uint32_t));
-
- if (req == SNEP_REQ_PUT && information_length == 0)
- {
-
- DEBUG_SERVER_MSG("no information data is exist");
- *resp_code = SNEP_RESP_BAD_REQ;
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return NET_NFC_OK;
-}
-
-static net_nfc_error_e _net_nfc_service_llcp_npp_check_req_msg(data_s* npp_msg, uint8_t* resp_code)
-{
- /* version check */
- /* action code check */
-
- if (npp_msg == NULL || npp_msg->buffer == NULL || resp_code == NULL)
- {
-
- return NET_NFC_NULL_PARAMETER;
- }
-
- *resp_code = 0;
-
- uint8_t* temp = NULL;
- uint8_t version = 0;
- bool is_supported_req = false;
- uint32_t ndef_entry_number = 0;
- uint8_t action_codes = 0;
-
- temp = npp_msg->buffer;
-
- /* get vesrion. and compare it with ours */
- version = *temp;
-
- if (version == 0)
- {
- DEBUG_SERVER_MSG("no version is set");
- *resp_code = NPP_RESP_UNSUPPORTED_VER;
- return NET_NFC_UNKNOWN_ERROR;
- }
- else
- {
- uint8_t major = (version & 0xf0) >> 4;
- uint8_t minor = (version & 0x0f);
-
- DEBUG_SERVER_MSG("major = [%d], minor = [%d]", major, minor);
-
- if (major != 0x00 || minor > 0x01)
- {
- DEBUG_SERVER_MSG("version is not matched");
- *resp_code = NPP_RESP_UNSUPPORTED_VER;
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- }
-
- /*Increase the address. Because we already get the version of the npp. so we have to get the "number of ndef entry" */
- temp++;
-
- /* get command */
- ndef_entry_number = ntohl(*((uint32_t *)(temp)));
-
- DEBUG_SERVER_MSG("check the number of ndef entry = [%d]", ndef_entry_number);
- temp += 4;
-
- /* action code*/
- memcpy(&action_codes, temp, sizeof(uint8_t));
-
- DEBUG_SERVER_MSG("check the action_codes = [%d]", action_codes);
-
- switch (action_codes)
- {
- case 0x01 :
- is_supported_req = true;
- break;
- default :
- is_supported_req = false;
- break;
-
- }
-
- if (is_supported_req == false)
- {
-
- DEBUG_SERVER_MSG("not supported action codes");
- *resp_code = NPP_RESP_NOT_IMPLEMEN;
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- temp++;
-
- uint32_t information_length = 0;
-
- memcpy(&information_length, temp, sizeof(uint32_t));
-
- if (action_codes != 0x01 || information_length == 0)
- {
-
- DEBUG_SERVER_MSG("no information data is exist");
- *resp_code = NPP_RESP_UNSUPPORTED_VER;
- return NET_NFC_UNKNOWN_ERROR;
- }
- return NET_NFC_OK;
-}
-
-static net_nfc_error_e _net_nfc_service_llcp_snep_get_code(data_s* snep_msg, uint8_t* code)
-{
- if (snep_msg == NULL || snep_msg->buffer == NULL || code == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- uint8_t* temp = NULL;
-
- temp = snep_msg->buffer;
-
- temp++;
-
- *code = *temp;
-
- return NET_NFC_OK;
-}
-
-static net_nfc_error_e _net_nfc_service_llcp_snep_get_information_length(data_s* snep_msg, uint32_t* length)
-{
- if (snep_msg == NULL || snep_msg->buffer == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- uint8_t* temp = NULL;
- uint32_t temp_length = 0;
-
- temp = snep_msg->buffer;
- temp += 2;
-
- /* change the length data as host order for compatibility with android */
- temp_length = ntohl(*((uint32_t *)(temp)));
- memcpy(length, &temp_length, sizeof(uint32_t));
-
- DEBUG_SERVER_MSG("check the snep ndef length [%d]", *length);
-
- return NET_NFC_OK;
-}
-
-static net_nfc_error_e _net_nfc_service_llcp_npp_get_information_length(data_s* npp_msg, uint32_t* length)
-{
- if (npp_msg == NULL || npp_msg->buffer == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- uint8_t* temp = NULL;
- uint32_t temp_length = 0;
-
- temp = npp_msg->buffer;
- temp += 6;
-
- DEBUG_SERVER_MSG("check the npp ndef length address= [%p]", temp);
-
- temp_length = ntohl(*((uint32_t *)(temp)));
- memcpy(length, &temp_length, sizeof(uint32_t));
-
- DEBUG_SERVER_MSG("check the npp ndef temp_length= [%d]", temp_length);
-
- DEBUG_SERVER_MSG("check the npp ndef length= [%d]", *length);
-
- return NET_NFC_OK;
-}
-
-static net_nfc_error_e _net_nfc_service_llcp_snep_check_resp_msg(data_s* snep_msg)
-{
- /* version check */
- /* command check */
-
- if (snep_msg == NULL || snep_msg->buffer == NULL)
- {
-
- return NET_NFC_NULL_PARAMETER;
- }
-
- uint8_t* temp = NULL;
- uint8_t version = 0;
- bool is_supported_resp = false;
- uint8_t resp = 0;
-
- temp = snep_msg->buffer;
-
- /* get vesrion. and compare it with ours */
- version = *temp;
-
- if (version == 0)
- {
- DEBUG_SERVER_MSG("version is wrong");
- return NET_NFC_UNKNOWN_ERROR;
- }
- else
- {
- uint8_t major = (version & 0xf0) >> 4;
- uint8_t minor = (version & 0x0f);
-
- DEBUG_SERVER_MSG("major[%d], minor[%d]", major, minor);
-
- if (major != SNEP_MAJOR_VER || minor > SNEP_MINOR_VER)
- {
- DEBUG_SERVER_MSG("version is not matched");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- }
-
- temp++;
-
- /* get command */
- resp = *temp;
- temp++;
-
- DEBUG_SERVER_MSG("result = [%d]", resp);
-
- switch (resp)
- {
- case SNEP_RESP_CONT :
- case SNEP_RESP_SUCCESS :
- case SNEP_RESP_NOT_FOUND :
- case SNEP_RESP_EXCESS_DATA :
- case SNEP_RESP_BAD_REQ :
- case SNEP_RESP_NOT_IMPLEMENT :
- case SNEP_RESP_UNSUPPORTED_VER :
- case SNEP_RESP_REJECT :
- is_supported_resp = true;
- break;
- default :
- is_supported_resp = false;
- break;
-
- }
-
- if (is_supported_resp == false)
- {
- DEBUG_SERVER_MSG("not supported resp command = [%d]", resp);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- uint32_t information_length = 0;
-
- memcpy(&information_length, temp, sizeof(uint32_t));
-
- if (resp != SNEP_RESP_SUCCESS && information_length != 0)
- {
- DEBUG_SERVER_MSG("error response should not have any information data");
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- return NET_NFC_OK;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_util_ndef_message.h"
-#include "net_nfc_util_ndef_record.h"
-#include "net_nfc_util_handover.h"
-
-#include "net_nfc_manager_util_private.h"
-#include "net_nfc_controller_private.h"
-#include "net_nfc_service_private.h"
-#include "net_nfc_service_llcp_private.h"
-#include "net_nfc_service_llcp_handover_private.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_server_context_private.h"
-
-#include "bluetooth-api.h"
-
-static uint8_t conn_handover_req_buffer[CH_MAX_BUFFER] = {0,};
-static uint8_t conn_handover_sel_buffer[CH_MAX_BUFFER] = {0,};
-
-static data_s conn_handover_req_data = {conn_handover_req_buffer, CH_MAX_BUFFER};
-static data_s conn_handover_sel_data = {conn_handover_sel_buffer, CH_MAX_BUFFER};
-
-static bool _net_nfc_service_llcp_check_hr_record_validation(ndef_message_s * message);
-static bool _net_nfc_service_llcp_check_hs_record_validation(ndef_message_s * message);
-
-net_nfc_error_e _net_nfc_service_llcp_create_low_power_selector_message(ndef_message_s *request_msg, ndef_message_s *select_msg);
-net_nfc_error_e net_nfc_service_llcp_handover_get_oob_data(net_nfc_carrier_config_s *config, bt_oob_data_t *oob);
-
-net_nfc_error_e net_nfc_service_llcp_handover_create_carrier_configs(ndef_message_s *msg, net_nfc_conn_handover_carrier_type_e type, bool requester, net_nfc_llcp_state_t *state, int next_step);
-int net_nfc_service_llcp_handover_append_bt_carrier_config(net_nfc_handover_create_config_context_t *context);
-int net_nfc_service_llcp_handover_append_wifi_carrier_config(net_nfc_handover_create_config_context_t *context);
-int net_nfc_service_llcp_handover_iterate_carrier_configs(net_nfc_handover_create_config_context_t *context);
-int net_nfc_service_llcp_handover_go_to_next_config(net_nfc_handover_create_config_context_t *context);
-static void _net_nfc_service_llcp_bt_create_config_cb(int event, bluetooth_event_param_t *param, void *user_data);
-
-net_nfc_error_e net_nfc_service_llcp_handover_process_carrier_config(net_nfc_carrier_config_s *config, bool requester, net_nfc_llcp_state_t *state, int next_step);
-int net_nfc_service_llcp_handover_process_bt_config(net_nfc_handover_process_config_context_t *context);
-
-int net_nfc_service_llcp_handover_return_to_step(net_nfc_handover_context_t *context);
-net_nfc_error_e net_nfc_service_llcp_handover_bt_change_data_order(net_nfc_carrier_config_s *config);
-
-net_nfc_error_e net_nfc_service_llcp_handover_send_request_msg(net_nfc_request_connection_handover_t *msg)
-{
- net_nfc_error_e error = NET_NFC_OK;
-
- DEBUG_SERVER_MSG("start");
-
- if (msg == NULL || msg->handle == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- net_nfc_llcp_state_t *conn_handover_requester = NULL;
- _net_nfc_util_alloc_mem(conn_handover_requester, sizeof(net_nfc_llcp_state_t));
- if (conn_handover_requester == NULL)
- {
- DEBUG_SERVER_MSG("conn_handover_requester is NULL");
- return NET_NFC_ALLOC_FAIL;
- }
-
- conn_handover_requester->client_fd = msg->client_fd;
- conn_handover_requester->handle = msg->handle;
- conn_handover_requester->state = NET_NFC_STATE_CONN_HANDOVER_REQUEST;
- conn_handover_requester->step = NET_NFC_LLCP_STEP_01;
- conn_handover_requester->type = msg->type;
-
- net_nfc_service_llcp_add_state(conn_handover_requester);
-
- if (net_nfc_service_llcp_connection_handover_requester(conn_handover_requester, &error) == true)
- {
- error = NET_NFC_OK;
- }
- else
- {
- DEBUG_SERVER_MSG("connection handover request is failed = [%d]", error);
- error = NET_NFC_OPERATION_FAIL;
- }
-
- return error;
-}
-
-bool net_nfc_service_llcp_create_server_socket(net_nfc_llcp_state_t *state, net_nfc_socket_type_e socket_type, uint16_t miu, uint8_t rw, int sap, char *san, net_nfc_error_e *result)
-{
- bool ret = false;
-
- if (result == NULL)
- {
- return ret;
- }
-
- if (state == NULL || san == NULL)
- {
- *result = NET_NFC_NULL_PARAMETER;
- return ret;
- }
-
- DEBUG_SERVER_MSG("begin net_nfc_service_llcp_create_server_socket");
-
- if ((ret = net_nfc_controller_llcp_create_socket(&(state->socket), socket_type, miu, rw, result, state)) == true)
- {
- DEBUG_SERVER_MSG("bind server socket with service acess point = [0x%x]", sap);
-
- if ((ret = net_nfc_controller_llcp_bind(state->socket, sap, result)) == true)
- {
- DEBUG_SERVER_MSG("listen server socket with service access name = [%s]", san);
-
- if ((ret = net_nfc_controller_llcp_listen(state->handle, (uint8_t *)san, state->socket, result, state)) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_llcp_listen success!!");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", *result);
- net_nfc_controller_llcp_socket_close(state->socket, result);
- state->socket = 0;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_bind failed [%d]", *result);
- net_nfc_controller_llcp_socket_close(state->socket, result);
- state->socket = 0;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", *result);
- }
-
- return ret;
-}
-
-static net_nfc_llcp_state_t *_net_nfc_service_llcp_add_new_state(int client_fd, net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, llcp_state_e state, unsigned int step, void *user_data)
-{
- net_nfc_llcp_state_t *context = NULL;
-
- LOGD("[%s] START", __func__);
-
- if (handle == NULL)
- {
- return context;
- }
-
- _net_nfc_util_alloc_mem(context, sizeof(net_nfc_llcp_state_t));
- if (context != NULL)
- {
- context->client_fd = client_fd;
- context->handle = handle;
- context->socket = socket;
- context->state = state;
- context->step = step;
- context->user_data = user_data;
-
- net_nfc_service_llcp_add_state(context);
- }
-
- LOGD("[%s] END", __func__);
-
- return context;
-}
-
-static void _net_nfc_service_llcp_handover_send_response(int socket, net_nfc_exchanger_event_e event, net_nfc_conn_handover_carrier_type_e type, data_s *data)
-{
- LOGD("[%s] START", __func__);
-
- if (net_nfc_server_check_client_is_running(socket) == true)
- {
- net_nfc_response_connection_handover_t resp_msg = { 0, };
-
- resp_msg.result = NET_NFC_OK;
- resp_msg.event = event;
-
- resp_msg.type = type;
- if (data != NULL && data->buffer != NULL && data->length != 0)
- {
- resp_msg.data.length = data->length;
- if (net_nfc_send_response_msg(socket, NET_NFC_MESSAGE_CONNECTION_HANDOVER, &resp_msg, sizeof(net_nfc_response_connection_handover_t), data->buffer, data->length, NULL) == true)
- {
- DEBUG_SERVER_MSG("send exchange message to client");
- }
- }
- else
- {
- if (net_nfc_send_response_msg(socket, NET_NFC_MESSAGE_CONNECTION_HANDOVER, &resp_msg, sizeof(net_nfc_response_connection_handover_t), NULL) == true)
- {
- DEBUG_SERVER_MSG("send exchange message to client");
- }
- }
- }
-
- LOGD("[%s] END", __func__);
-}
-
-static bool _net_nfc_service_llcp_send_ndef_message(net_nfc_llcp_state_t *state, ndef_message_s *msg, net_nfc_error_e *result)
-{
- bool ret = false;
- data_s send_data = { NULL, 0 };
-
- LOGD("[%s] START", __func__);
-
- if (result == NULL)
- {
- return ret;
- }
-
- if (state == NULL || msg == NULL)
- {
- *result = NET_NFC_NULL_PARAMETER;
- return ret;
- }
-
- send_data.length = net_nfc_util_get_ndef_message_length(msg);
-
- if (send_data.length > 0)
- {
- _net_nfc_util_alloc_mem(send_data.buffer, send_data.length);
- if (send_data.buffer != NULL)
- {
- if ((*result =net_nfc_util_convert_ndef_message_to_rawdata(msg, &send_data)) == NET_NFC_OK)
- {
- if ((ret = net_nfc_controller_llcp_send(state->handle, state->socket, &send_data, result, state)) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_llcp_send success!!");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed [%d]", *result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_ndef_to_rawdata failed [%d]", *result);
- }
-
- _net_nfc_util_free_mem(send_data.buffer);
- }
- else
- {
- *result = NET_NFC_ALLOC_FAIL;
- }
- }
- else
- {
- *result = NET_NFC_INVALID_PARAM;
- }
-
- LOGD("[%s] END", __func__);
-
- return ret;
-}
-
-net_nfc_error_e _net_nfc_service_llcp_get_carrier_record_by_priority_order(ndef_message_s *request_msg, ndef_record_s **record)
-{
- net_nfc_error_e result = NET_NFC_INVALID_PARAM;
- unsigned int carrier_count = 0;
-
- LOGD("[%s] START", __func__);
-
- if (request_msg == NULL || record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((result = net_nfc_util_get_alternative_carrier_record_count(request_msg, &carrier_count)) == NET_NFC_OK)
- {
- int idx, priority;
- net_nfc_conn_handover_carrier_type_e carrier_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- /* apply priority (order NET_NFC_CONN_HANDOVER_CARRIER_BT ~ NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS) */
- for (priority = NET_NFC_CONN_HANDOVER_CARRIER_BT; *record == NULL && priority < NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN; priority++)
- {
- /* check each carrier record and create matched record */
- for (idx = 0; idx < carrier_count; idx++)
- {
- if ((net_nfc_util_get_alternative_carrier_type(request_msg, idx, &carrier_type) == NET_NFC_OK) && (carrier_type == priority))
- {
- DEBUG_SERVER_MSG("selected carrier type = [%d]", carrier_type);
- net_nfc_util_get_carrier_config_record(request_msg, idx, record);
- result = NET_NFC_OK;
- break;
- }
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed");
- }
-
- LOGD("[%s] END", __func__);
-
- return result;
-}
-
-static net_nfc_error_e _net_nfc_service_handover_create_requester_message_from_rawdata(ndef_message_s **request_msg, data_s *data)
-{
- net_nfc_error_e result;
-
- if ((result = net_nfc_util_create_ndef_message(request_msg)) == NET_NFC_OK)
- {
- if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data, *request_msg)) == NET_NFC_OK)
- {
- if (_net_nfc_service_llcp_check_hr_record_validation(*request_msg) == true)
- {
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("record is not valid or is not available");
- result = NET_NFC_INVALID_PARAM;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef failed [%d]", result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", result);
- }
-
- return result;
-}
-
-bool net_nfc_service_llcp_connection_handover_selector(net_nfc_llcp_state_t *state, net_nfc_error_e *result)
-{
- bool need_clean_up = false;
-
- LOGD("[%s] START", __func__);
-
- if (result == NULL)
- {
- DEBUG_SERVER_MSG("result is NULL");
- return false;
- }
-
- *result = NET_NFC_OK;
-
- switch (state->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- {
- DEBUG_SERVER_MSG("step 1");
-
- if (net_nfc_service_llcp_create_server_socket(state, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, CH_MAX_BUFFER, 1, CONN_HANDOVER_SAP, CONN_HANDOVER_SAN, result) == true)
- {
- state->step = NET_NFC_LLCP_STEP_02;
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- DEBUG_SERVER_MSG("step 2");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover selector: listen is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- net_nfc_llcp_state_t *new_client = _net_nfc_service_llcp_add_new_state(state->client_fd, state->handle, state->incomming_socket, state->state, NET_NFC_LLCP_STEP_03, NULL);
- if (new_client != NULL)
- {
- memset(conn_handover_sel_data.buffer, 0x00, CH_MAX_BUFFER);
- conn_handover_sel_data.length = CH_MAX_BUFFER;
-
- if (net_nfc_controller_llcp_recv(new_client->handle, new_client->socket, &conn_handover_sel_data, result, new_client) == false)
- {
- DEBUG_ERR_MSG("net_nfc_controller_llcp_recv failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_service_llcp_add_new_state returns NULL");
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- {
- DEBUG_SERVER_MSG("step 3");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover selector : receive is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- DEBUG_SERVER_MSG("handover selector : receiving is successful");
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- /* process and send message */
- /* get requester message */
- if ((*result = _net_nfc_service_handover_create_requester_message_from_rawdata(&state->requester, &conn_handover_sel_data)) == NET_NFC_OK)
- {
- unsigned int count = 0;
-
- if ((*result = net_nfc_util_get_alternative_carrier_record_count(state->requester, &count)) == NET_NFC_OK)
- {
- /* create selector message */
- if ((*result = net_nfc_util_create_handover_select_message(&state->selector)) == NET_NFC_OK)
- {
- if (1/* power state */ || count == 1)
- {
- ndef_record_s *record = NULL;
-
- /* fill alternative carrier information */
- if ((*result = _net_nfc_service_llcp_get_carrier_record_by_priority_order(state->requester, &record)) == NET_NFC_OK)
- {
- net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- if ((*result = net_nfc_util_get_alternative_carrier_type_from_record(record, &type)) == NET_NFC_OK)
- {
- if ((*result = net_nfc_service_llcp_handover_create_carrier_configs(state->selector, type, false, state, NET_NFC_LLCP_STEP_04)) != NET_NFC_OK)
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("net_nfc_service_llcp_handover_create_carrier_configs failed [%d]", *result);
- }
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_type_from_record failed [%d]", *result);
- }
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("_net_nfc_service_llcp_get_carrier_record_by_priority_order failed [%d]", *result);
- }
- }
- else /* low power && count > 1 */
- {
- state->low_power = true;
-
- if ((*result = _net_nfc_service_llcp_create_low_power_selector_message(state->requester, state->selector)) == NET_NFC_OK)
- {
- state->step = NET_NFC_LLCP_STEP_06;
- net_nfc_service_llcp_connection_handover_selector(state, result);
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("_net_nfc_service_llcp_create_low_power_selector_message failed [%d]", *result);
- }
- }
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("net_nfc_util_create_handover_select_message failed [%d]", *result);
- }
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed [%d]", *result);
- }
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("_net_nfc_service_handover_create_requester_message_from_rawdata failed [%d]", *result);
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- {
- ndef_record_s *record = NULL;
-
- DEBUG_SERVER_MSG("step 4");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover selector : recevie is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- /* fill alternative carrier information */
- if ((*result = _net_nfc_service_llcp_get_carrier_record_by_priority_order(state->requester, &record)) == NET_NFC_OK)
- {
- net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- DEBUG_SERVER_MSG("record [%p]", record);
-
- if ((*result = net_nfc_util_get_alternative_carrier_type_from_record(record, &type)) == NET_NFC_OK)
- {
- net_nfc_carrier_config_s *config = NULL;
-
- DEBUG_SERVER_MSG("type [%d]", type);
-
- *result = net_nfc_util_create_carrier_config_from_config_record(&config, record);
-
- DEBUG_SERVER_MSG("config [%p]", config);
-
- *result = net_nfc_service_llcp_handover_process_carrier_config(config, false, state, NET_NFC_LLCP_STEP_05);
-
- if (*result != NET_NFC_OK && *result != NET_NFC_BUSY)
- {
- DEBUG_ERR_MSG("net_nfc_service_llcp_handover_process_carrier_config failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
-
- DEBUG_SERVER_MSG("after net_nfc_service_llcp_handover_process_carrier_config");
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_type_from_record failed [%d]", *result);
- }
- }
- else
- {
- state->step = NET_NFC_STATE_ERROR;
- DEBUG_ERR_MSG("_net_nfc_service_llcp_get_carrier_record_by_priority_order failed [%d]", *result);
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_05 :
- {
- DEBUG_SERVER_MSG("step 5");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover selector : recevie is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- /* send ndef message via llcp */
- if (_net_nfc_service_llcp_send_ndef_message(state, state->selector, result) == true)
- {
- DEBUG_SERVER_MSG("handover selector : sending select msg is success");
-
- if (state->low_power == true)
- {
- DEBUG_SERVER_MSG("activate_forced == false, next step is NET_NFC_LLCP_STEP_02");
- state->step = NET_NFC_LLCP_STEP_02;
- }
- else
- {
- DEBUG_SERVER_MSG("next step is NET_NFC_LLCP_STEP_06");
- state->step = NET_NFC_LLCP_STEP_06;
- }
- }
- else
- {
- DEBUG_ERR_MSG("handover selector : sending select msg is failed [%d]", *result);
- }
-
- if (*result == NET_NFC_OK || *result == NET_NFC_BUSY)
- {
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_service_llcp_send_selector_ndef_message failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_06 :
- {
- DEBUG_SERVER_MSG("step 6");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover selector : send ndef failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- net_nfc_util_free_ndef_message(state->requester);
- net_nfc_util_free_ndef_message(state->selector);
-
- state->step = 0;
- }
- break;
-
- case NET_NFC_STATE_SOCKET_ERROR :
- {
- DEBUG_SERVER_MSG("conn handover selector : socket error is received %d", state->prev_result);
- need_clean_up = true;
- }
- break;
-
- default :
- {
- DEBUG_SERVER_MSG("unknown step");
- need_clean_up = true;
- }
- break;
- }
-
- if (state->step == NET_NFC_STATE_ERROR)
- {
- net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR);
- state->step = 0;
- }
-
- if (need_clean_up == true)
- {
- net_nfc_controller_llcp_socket_close(state->socket, result);
- net_nfc_service_llcp_remove_state(state);
- _net_nfc_util_free_mem(state);
- }
-
- if (*result != NET_NFC_BUSY && *result != NET_NFC_OK)
- {
- return false;
- }
-
- LOGD("[%s] END", __func__);
-
- return true;
-}
-
-net_nfc_error_e _net_nfc_service_llcp_create_requester_ndef_message(net_nfc_llcp_state_t *state)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- net_nfc_conn_handover_carrier_type_e carrier_type;
-
- LOGD("[%s] START", __func__);
-
- if (state->requester == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- carrier_type = state->type;
-
- if (state->selector != NULL)
- {
- /* selector is low power state... so request one alternative carrier */
- if ((result = net_nfc_util_get_alternative_carrier_type(state->selector, 0, &carrier_type)) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("select_msg 0 carrier type [%d]", carrier_type);
- }
- }
-
- if ((result = net_nfc_service_llcp_handover_create_carrier_configs(state->requester, carrier_type, true, state, NET_NFC_LLCP_STEP_03)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_service_llcp_handover_create_carrier_configs failed [%d]", result);
- }
-
- LOGD("[%s] END", __func__);
-
- return result;
-}
-
-net_nfc_error_e _net_nfc_service_llcp_get_carrier_record(ndef_message_s *select_msg, ndef_record_s **carrier_record)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- unsigned int carrier_count;
-
- LOGD("[%s] START", __func__);
-
- if (select_msg == NULL || carrier_record == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- /* connect selected carrier... :) */
- if ((result = net_nfc_util_get_alternative_carrier_record_count(select_msg, &carrier_count)) == NET_NFC_OK)
- {
- int idx;
- net_nfc_conn_handover_carrier_type_e carrier_type;
-
- for (idx = 0; idx < carrier_count; idx++)
- {
- if ((result = net_nfc_util_get_alternative_carrier_type(select_msg, idx, &carrier_type)) == NET_NFC_OK)
- {
- net_nfc_conn_handover_carrier_state_e cps;
-
- cps = net_nfc_util_get_cps(carrier_type);
-
- switch (carrier_type)
- {
- case NET_NFC_CONN_HANDOVER_CARRIER_BT :
- DEBUG_SERVER_MSG("if bt is off, then turn on");
- if (cps != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE && cps != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING)
- {
- DEBUG_SERVER_MSG("turn on bt");
- net_nfc_util_enable_bluetooth();
- }
-
- net_nfc_util_get_carrier_config_record(select_msg, idx, carrier_record);
- break;
-
- default :
- continue;
- }
-
- if (*carrier_record != NULL)
- {
- result = NET_NFC_OK;
- break;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_type failed [%d]", result);
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed [%d]", result);
- }
-
- LOGD("[%s] END", __func__);
-
- return result;
-}
-
-static net_nfc_error_e _net_nfc_service_handover_create_selector_message_from_rawdata(ndef_message_s **select_msg, data_s *data)
-{
- net_nfc_error_e result;
-
- if (select_msg == NULL)
- return NET_NFC_NULL_PARAMETER;
-
- if ((result = net_nfc_util_create_ndef_message(select_msg)) == NET_NFC_OK)
- {
- if ((result = net_nfc_util_convert_rawdata_to_ndef_message(data, *select_msg)) == NET_NFC_OK)
- {
- /* if record is not Hs record, then */
- if (_net_nfc_service_llcp_check_hs_record_validation(*select_msg) == true)
- {
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("record is not valid or is not available");
- result = NET_NFC_INVALID_PARAM;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_ndef_rawdata_to_ndef failed [%d]", result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_create_ndef_message failed [%d]", result);
- }
-
- return result;
-}
-
-bool net_nfc_service_llcp_connection_handover_requester(net_nfc_llcp_state_t *state, net_nfc_error_e *result)
-{
- bool need_clean_up = false;
-
- LOGD("[%s] START", __func__);
-
- if (state == NULL || result == NULL)
- {
- DEBUG_SERVER_MSG("state/result is NULL");
- return false;
- }
-
- *result = NET_NFC_OK;
-
- switch (state->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- {
- DEBUG_SERVER_MSG("step 1");
-
- if (net_nfc_controller_llcp_create_socket(&(state->socket), NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, CH_MAX_BUFFER, 1, result, state) == false)
- {
- DEBUG_SERVER_MSG("creating socket is failed");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- DEBUG_SERVER_MSG("connect to remote server with socket = [0x%x]", state->socket);
-
- state->step = NET_NFC_LLCP_STEP_02;
-
- if (net_nfc_controller_llcp_connect_by_url(state->handle, state->socket, (uint8_t *)CONN_HANDOVER_SAN, result, state) == false)
- {
- DEBUG_SERVER_MSG("making connection is failed");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- DEBUG_SERVER_MSG("step 2");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover requester : connect is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_03;
-
- if ((*result = net_nfc_util_create_handover_request_message(&state->requester)) == NET_NFC_OK)
- {
- net_nfc_conn_handover_carrier_type_e carrier_type;
-
- if (state->selector != NULL)
- {
- /* selector is low power state... so request one alternative carrier */
- if ((*result = net_nfc_util_get_alternative_carrier_type(state->selector, 0, &carrier_type)) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("select_msg 0 carrier type [%d]", carrier_type);
- }
- else
- {
- DEBUG_SERVER_MSG("select_msg 0 carrier type failed [%d]", *result);
-
- carrier_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
- }
-
- net_nfc_util_free_ndef_message(state->selector);
- state->selector = NULL;
- }
- else
- {
- carrier_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
- }
-
- if ((*result = net_nfc_service_llcp_handover_create_carrier_configs(state->requester, carrier_type, true, state, NET_NFC_LLCP_STEP_03)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_service_llcp_handover_create_carrier_configs failed [%d]", *result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("handover requester : sending select msg is failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- {
- DEBUG_SERVER_MSG("step 3");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover requester : connect is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_04;
-
- /* send ndef message via llcp */
- if (_net_nfc_service_llcp_send_ndef_message(state, state->requester, result) == true)
- {
- DEBUG_SERVER_MSG("handover requester : sending request msg is success");
- }
- else
- {
- DEBUG_ERR_MSG("handover requester : sending request msg is failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
-
- net_nfc_util_free_ndef_message(state->requester);
- state->requester = NULL;
- }
- break;
-
- case NET_NFC_LLCP_STEP_04 :
- {
- DEBUG_SERVER_MSG("step 4");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover requester : connect is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- state->step = NET_NFC_LLCP_STEP_05;
-
- memset(conn_handover_req_data.buffer, 0x00, CH_MAX_BUFFER);
- conn_handover_req_data.length = CH_MAX_BUFFER;
-
- if (net_nfc_controller_llcp_recv(state->handle, state->socket, &conn_handover_req_data, result, state) == false)
- {
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_05 :
- {
- DEBUG_SERVER_MSG("step 5");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover requester : receiving is failed...");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- DEBUG_SERVER_MSG("handover requster : receiving is successful");
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- if ((*result = _net_nfc_service_handover_create_selector_message_from_rawdata(&state->selector, &conn_handover_req_data)) == NET_NFC_OK)
- {
- net_nfc_conn_handover_carrier_state_e power_state = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
-
- /* check selector power state */
- if ((*result = net_nfc_util_get_selector_power_status(state->selector, &power_state)) == NET_NFC_OK)
- {
- DEBUG_MSG("power_state == %d", power_state);
-
- if (power_state == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE || power_state == NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING)
- {
- ndef_record_s *carrier_record = NULL;
-
- if ((*result = _net_nfc_service_llcp_get_carrier_record(state->selector, &carrier_record)) == NET_NFC_OK)
- {
- net_nfc_carrier_config_s *handover_config = NULL;
-
- if ((*result = net_nfc_util_create_carrier_config_from_config_record(&handover_config, carrier_record)) == NET_NFC_OK)
- {
- net_nfc_service_llcp_handover_process_carrier_config(handover_config, true, state, NET_NFC_LLCP_STEP_06);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_create_carrier_config_from_config_record failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- else
- {
- /* go to step 2 */
- state->step = NET_NFC_LLCP_STEP_02;
- net_nfc_service_llcp_connection_handover_requester(state, result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_selector_power_status failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_service_handover_create_selector_message_from_rawdata failed [%d]", *result);
- state->step = NET_NFC_STATE_ERROR;
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_06 :
- {
- DEBUG_SERVER_MSG("step 6");
-
- if (state->prev_result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("handover requester : processing failed");
- state->step = NET_NFC_STATE_ERROR;
- break;
- }
-
- net_nfc_util_free_ndef_message(state->requester);
- net_nfc_util_free_ndef_message(state->selector);
-
- state->step = 0;
- }
- break;
-
- case NET_NFC_STATE_SOCKET_ERROR :
- {
- DEBUG_SERVER_MSG("exchange server: socket error is received %d", state->prev_result);
- need_clean_up = true;
- }
- break;
-
- default :
- {
- DEBUG_SERVER_MSG("unknown step");
- need_clean_up = true;
- }
- break;
-
- }
-
- if (state->step == NET_NFC_STATE_ERROR)
- {
- net_nfc_manager_util_play_sound(NET_NFC_TASK_ERROR);
- _net_nfc_service_llcp_handover_send_response(state->client_fd, NET_NFC_OPERATION_FAIL, NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN, NULL);
- net_nfc_util_free_ndef_message(state->requester);
- net_nfc_util_free_ndef_message(state->selector);
- state->step = 0;
- }
-
- if (need_clean_up == true)
- {
- net_nfc_util_free_ndef_message(state->requester);
- net_nfc_util_free_ndef_message(state->selector);
- net_nfc_controller_llcp_socket_close(state->socket, result);
- net_nfc_service_llcp_remove_state(state);
- _net_nfc_util_free_mem(state);
- }
-
- if (*result != NET_NFC_BUSY && *result != NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("result is = [%d]", *result);
- return false;
- }
-
- LOGD("[%s] END", __func__);
-
- return true;
-}
-
-static bool _net_nfc_service_llcp_check_hr_record_validation(ndef_message_s *message)
-{
- unsigned int count;
- ndef_record_s *rec;
-
- LOGD("[%s] START", __func__);
-
- if (message == NULL)
- return false;
-
- rec = (ndef_record_s *)message->records;
-
- if (memcmp(rec->type_s.buffer, CONN_HANDOVER_REQ_RECORD_TYPE, rec->type_s.length) != 0)
- {
- DEBUG_SERVER_MSG("This is not connection handover request message");
- return false;
- }
-
- if (rec->payload_s.buffer[0] != 0x12)
- {
- DEBUG_SERVER_MSG("connection handover version is not matched");
- return false;
- }
-
- if (net_nfc_util_get_alternative_carrier_record_count(message, &count) != NET_NFC_OK || count == 0)
- {
- DEBUG_SERVER_MSG("there is no carrrier reference");
- return false;
- }
-
- LOGD("[%s] END", __func__);
-
- return true;
-}
-
-static bool _net_nfc_service_llcp_check_hs_record_validation(ndef_message_s *message)
-{
- unsigned int count;
- ndef_record_s *rec;
-
- LOGD("[%s] START", __func__);
-
- if (message == NULL)
- return false;
-
- rec = (ndef_record_s *)message->records;
-
- if (memcmp(rec->type_s.buffer, CONN_HANDOVER_SEL_RECORD_TYPE, rec->type_s.length) != 0)
- {
- DEBUG_SERVER_MSG("This is not connection handover request message");
- return false;
- }
-
- if (net_nfc_util_get_alternative_carrier_record_count(message, &count) != NET_NFC_OK || count == 0)
- {
- DEBUG_SERVER_MSG("there is no carrrier reference");
- return false;
- }
-
- /* Contant should be replaced to get api */
- if (rec->payload_s.buffer[0] != 0x12)
- {
- DEBUG_SERVER_MSG("connection handover version is not matched");
- return false;
- }
-
- LOGD("[%s] END", __func__);
-
- return true;
-}
-
-static bool _net_nfc_service_llcp_handover_check_bond_device(bluetooth_device_address_t *address)
-{
- bool result = false;
- int i, ret;
- GPtrArray *devinfo = NULL;
- bluetooth_device_info_t *ptr;
-
- LOGD("[%s] START", __func__);
-
- /* allocate the g_pointer_array */
- devinfo = g_ptr_array_new();
-
- ret = bluetooth_get_bonded_device_list(&devinfo);
- if (ret != BLUETOOTH_ERROR_NONE)
- {
- DEBUG_ERR_MSG("bluetooth_get_bonded_device_list failed with [%d]", ret);
- }
- else
- {
- DEBUG_SERVER_MSG("g pointer arrary count : [%d]", devinfo->len);
- for (i = 0; i < devinfo->len; i++)
- {
- ptr = g_ptr_array_index(devinfo, i);
- if (ptr != NULL)
- {
- DEBUG_SERVER_MSG("Name [%s]", ptr->device_name.name);
- DEBUG_SERVER_MSG("Major Class [%d]", ptr->device_class.major_class);
- DEBUG_SERVER_MSG("Minor Class [%d]", ptr->device_class.minor_class);
- DEBUG_SERVER_MSG("Service Class [%d]", ptr->device_class.service_class);
- DEBUG_SERVER_MSG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
- ptr->device_address.addr[0],
- ptr->device_address.addr[1], ptr->device_address.addr[2],
- ptr->device_address.addr[3],
- ptr->device_address.addr[4], ptr->device_address.addr[5]);
-
- /* compare selector address */
- if (memcmp(&(ptr->device_address), address, sizeof(ptr->device_address)) == 0)
- {
- DEBUG_SERVER_MSG("Found!!!");
- result = true;
- break;
- }
- }
- }
- }
-
- /* free g_pointer_array */
- g_ptr_array_free(devinfo, TRUE);
-
- LOGD("[%s] END", __func__);
-
- return result;
-}
-
-static void _net_nfc_service_llcp_bt_create_config_cb(int event, bluetooth_event_param_t *param, void *user_data)
-{
- net_nfc_handover_create_config_context_t *context = (net_nfc_handover_create_config_context_t *)user_data;
-
- LOGD("[%s] START", __func__);
-
- if (context == NULL)
- {
- DEBUG_SERVER_MSG("user_data is null");
- LOGD("[%s] END", __func__);
- return;
- }
-
- switch (event)
- {
- case BLUETOOTH_EVENT_ENABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
- if (context->step == NET_NFC_LLCP_STEP_02)
- {
- net_nfc_service_llcp_handover_append_bt_carrier_config(context);
- }
- else
- {
- DEBUG_SERVER_MSG("step is incorrect");
- }
- break;
-
- case BLUETOOTH_EVENT_DISABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
- break;
-
- default :
- DEBUG_SERVER_MSG("unhandled bt event [%d], [0x%04x]", event, param->result);
- break;
- }
-
- LOGD("[%s] END", __func__);
-}
-
-int net_nfc_service_llcp_handover_return_to_step(net_nfc_handover_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (context != NULL)
- {
- net_nfc_llcp_state_t *state = context->llcp_state;
- net_nfc_error_e error = NET_NFC_OK;
- bool requester = context->is_requester;
-
- DEBUG_MSG("free context [%p]", context);
- _net_nfc_util_free_mem(context);
-
- if (requester)
- {
- net_nfc_service_llcp_connection_handover_requester(state, &error);
- }
- else
- {
- net_nfc_service_llcp_connection_handover_selector(state, &error);
- }
- }
- else
- {
- DEBUG_ERR_MSG("null param");
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-int net_nfc_service_llcp_handover_go_to_next_config(net_nfc_handover_create_config_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (context->result == NET_NFC_OK || context->result == NET_NFC_BUSY)
- {
- if (context->request_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
- {
- if (context->current_type < NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
- {
- context->current_type++;
- }
- }
- else
- {
- context->current_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
- }
-
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_iterate_carrier_configs, (gpointer)context);
- }
- else
- {
- DEBUG_ERR_MSG("context->result is error [%d]", context->result);
-
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_return_to_step, (gpointer)context);
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-int net_nfc_service_llcp_handover_iterate_carrier_configs(net_nfc_handover_create_config_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- switch (context->current_type)
- {
- case NET_NFC_CONN_HANDOVER_CARRIER_BT :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]");
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_bt_carrier_config, (gpointer)context);
- break;
-
-// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
-// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
-// g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_wifi_carrier_config, context);
-// break;
-//
-// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
-// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
-// g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_wifi_carrier_config, context);
-// break;
-//
- case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_return_to_step, (gpointer)context);
- break;
-
- default :
- DEBUG_MSG("[unknown : %d]", context->current_type);
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_go_to_next_config, (gpointer)context);
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-net_nfc_error_e net_nfc_service_llcp_handover_create_carrier_configs(ndef_message_s *msg, net_nfc_conn_handover_carrier_type_e type, bool requester, net_nfc_llcp_state_t *state, int next_step)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_handover_create_config_context_t *context = NULL;
-
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- _net_nfc_util_alloc_mem(context, sizeof(net_nfc_handover_create_config_context_t));
- if (context != NULL)
- {
- state->step = next_step;
-
- context->request_type = type;
- context->current_type = context->request_type;
- if (context->request_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
- context->current_type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
- context->is_requester = requester;
- context->llcp_state = state;
- context->step = NET_NFC_LLCP_STEP_01;
- context->ndef_message = msg;
-
- /* append carrier record */
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_iterate_carrier_configs, (gpointer)context);
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- result = NET_NFC_ALLOC_FAIL;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return result;
-}
-
-int net_nfc_service_llcp_handover_append_bt_carrier_config(net_nfc_handover_create_config_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
- {
- DEBUG_ERR_MSG("context->result is error [%d]", context->result);
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- }
-
- switch (context->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_MSG("STEP [1]");
-
- if (bluetooth_register_callback(_net_nfc_service_llcp_bt_create_config_cb, context) >= BLUETOOTH_ERROR_NONE)
- {
- context->step = NET_NFC_LLCP_STEP_02;
- context->result = NET_NFC_OK;
-
- if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED)
- {
- bluetooth_enable_adapter();
- }
- else
- {
- DEBUG_MSG("bluetooth is enabled already");
-
- /* do next step */
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_bt_carrier_config, (gpointer)context);
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth_register_callback failed");
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- context->result = NET_NFC_OPERATION_FAIL;
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_bt_carrier_config, (gpointer)context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- net_nfc_carrier_config_s *config = NULL;
- ndef_record_s *record = NULL;
- bluetooth_device_address_t bt_addr = { { 0, } };
-
- DEBUG_MSG("STEP [2]");
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
-
- /* append config to ndef message */
- if ((result = bluetooth_get_local_address(&bt_addr)) == BLUETOOTH_ERROR_NONE)
- {
- if ((result = net_nfc_util_create_carrier_config(&config, NET_NFC_CONN_HANDOVER_CARRIER_BT)) == NET_NFC_OK)
- {
- bt_oob_data_t oob = { { 0 }, };
-
- if ((result = net_nfc_util_add_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_ADDRESS, sizeof(bt_addr.addr), bt_addr.addr)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result);
- }
-
- /* get oob data */
- bluetooth_oob_read_local_data(&oob);
-
- if (oob.hash_len == 16)
- {
- DEBUG_SERVER_MSG("oob.hash_len [%d]", oob.hash_len);
-
- if ((result = net_nfc_util_add_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, oob.hash_len, oob.hash)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result);
- }
- }
-
- if (oob.randomizer_len == 16)
- {
- DEBUG_SERVER_MSG("oob.randomizer_len [%d]", oob.randomizer_len);
-
- if ((result = net_nfc_util_add_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, oob.randomizer_len, oob.randomizer)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed [%d]", result);
- }
- }
-
- net_nfc_service_llcp_handover_bt_change_data_order(config);
-
- if ((result = net_nfc_util_create_ndef_record_with_carrier_config(&record, config)) == NET_NFC_OK)
- {
- if ((result = net_nfc_util_append_carrier_config_record(context->ndef_message, record, 0)) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("net_nfc_util_append_carrier_config_record success");
-
- context->result = result;
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_append_carrier_config_record failed [%d]", result);
-
- net_nfc_util_free_record(record);
- context->result = result;
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_create_ndef_record_with_carrier_config failed [%d]", result);
- context->result = NET_NFC_OPERATION_FAIL;
- }
-
- net_nfc_util_free_carrier_config(config);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_create_carrier_config failed [%d]", result);
- context->result = NET_NFC_OPERATION_FAIL;
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth_get_local_address failed [%d]", result);
- context->result = NET_NFC_OPERATION_FAIL;
- }
-
- /* complete and return to upper step */
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_append_bt_carrier_config, (gpointer)context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- DEBUG_MSG("STEP return");
-
- /* unregister current callback */
- bluetooth_unregister_callback();
-
- /* complete and return to upper step */
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_go_to_next_config, (gpointer)context);
- break;
-
- default :
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-int net_nfc_service_llcp_handover_append_wifi_carrier_config(net_nfc_handover_create_config_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- switch (context->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_MSG("STEP [1]");
-
- context->step = NET_NFC_LLCP_STEP_02;
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- DEBUG_MSG("STEP [2]");
-
- context->step = NET_NFC_LLCP_STEP_03;
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- DEBUG_MSG("STEP [3]");
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- DEBUG_MSG("STEP return");
-
- /* complete and return to upper step */
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_go_to_next_config, (gpointer)context);
- break;
-
- default :
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-net_nfc_error_e _net_nfc_service_llcp_create_low_power_selector_message(ndef_message_s *request_msg, ndef_message_s *select_msg)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- unsigned int carrier_count = 0;
-
- LOGD("[%s] START", __func__);
-
- if (request_msg == NULL || select_msg == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((result = net_nfc_util_get_alternative_carrier_record_count(request_msg, &carrier_count)) == NET_NFC_OK)
- {
- int idx;
- ndef_record_s *carrier_record = NULL;
- net_nfc_conn_handover_carrier_type_e carrier_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- /* check each carrier record and create matched record */
- for (idx = 0; idx < carrier_count; idx++)
- {
- if ((net_nfc_util_get_alternative_carrier_type(request_msg, idx, &carrier_type) != NET_NFC_OK) ||
- (carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN))
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_type failed or unknown");
- continue;
- }
-
- DEBUG_SERVER_MSG("carrier type = [%d]", carrier_type);
-
- /* add temporary config record */
- {
- net_nfc_carrier_config_s *config = NULL;
-
- if ((result = net_nfc_util_create_carrier_config(&config, carrier_type)) == NET_NFC_OK)
- {
- if ((result = net_nfc_util_create_ndef_record_with_carrier_config(&carrier_record, config)) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("_net_nfc_service_llcp_create_bt_configuration success");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_create_ndef_record_with_carrier_config failed [%d]", result);
- net_nfc_util_free_carrier_config(config);
- continue;
- }
-
- net_nfc_util_free_carrier_config(config);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_local_bt_address return NULL");
- continue;
- }
- }
-
- /* append carrier configure record to selector message */
- if ((result = net_nfc_util_append_carrier_config_record(select_msg, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE)) == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("net_nfc_util_append_carrier_config_record success!!");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_append_carrier_config_record failed [%d]", result);
-
- net_nfc_util_free_record(carrier_record);
- }
- }
-
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count failed");
- }
-
- LOGD("[%s] END", __func__);
-
- return result;
-}
-
-static void _net_nfc_service_llcp_process_bt_config_cb(int event, bluetooth_event_param_t *param, void *user_data)
-{
- net_nfc_handover_process_config_context_t *context = (net_nfc_handover_process_config_context_t *)user_data;
-
- LOGD("[%s] START", __func__);
-
- if (context == NULL)
- {
- DEBUG_SERVER_MSG("user_data is null");
- LOGD("[%s] END", __func__);
- return;
- }
-
- switch (event)
- {
- case BLUETOOTH_EVENT_ENABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_ENABLED");
- if (context->step == NET_NFC_LLCP_STEP_02)
- {
- net_nfc_service_llcp_handover_process_bt_config(context);
- }
- else
- {
- DEBUG_SERVER_MSG("step is incorrect");
- }
- break;
-
- case BLUETOOTH_EVENT_DISABLED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_DISABLED");
- break;
-
- case BLUETOOTH_EVENT_BONDING_FINISHED :
- DEBUG_SERVER_MSG("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result);
- if (context->step == NET_NFC_LLCP_STEP_03)
- {
- if (param->result < BLUETOOTH_ERROR_NONE)
- {
- DEBUG_ERR_MSG("bond failed");
- context->result = NET_NFC_OPERATION_FAIL;
- }
-
- net_nfc_service_llcp_handover_process_bt_config(context);
- }
- else
- {
- DEBUG_SERVER_MSG("step is incorrect");
- }
- break;
-
- default :
- DEBUG_SERVER_MSG("unhandled bt event [%d], [0x%04x]", event, param->result);
- break;
- }
-
- LOGD("[%s] END", __func__);
-}
-
-net_nfc_error_e net_nfc_service_llcp_handover_process_carrier_config(net_nfc_carrier_config_s *config, bool requester, net_nfc_llcp_state_t *state, int next_step)
-{
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_handover_process_config_context_t *context = NULL;
-
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- _net_nfc_util_alloc_mem(context, sizeof(net_nfc_handover_process_config_context_t));
- if (context != NULL)
- {
- state->step = next_step;
-
- context->request_type = config->type;
- context->is_requester = requester;
- context->llcp_state = state;
- context->step = NET_NFC_LLCP_STEP_01;
- context->config = config;
-
- /* append carrier record */
- switch (config->type)
- {
- case NET_NFC_CONN_HANDOVER_CARRIER_BT :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_BT]");
- net_nfc_service_llcp_handover_bt_change_data_order(context->config);
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context);
- break;
-
- case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
- _net_nfc_util_free_mem(context);
- break;
-
- case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
- DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN]");
- _net_nfc_util_free_mem(context);
- break;
-
- default :
- DEBUG_MSG("[unknown]");
- _net_nfc_util_free_mem(context);
- break;
- }
- }
- else
- {
- DEBUG_ERR_MSG("alloc failed");
- result = NET_NFC_ALLOC_FAIL;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return result;
-}
-
-int net_nfc_service_llcp_handover_process_bt_config(net_nfc_handover_process_config_context_t *context)
-{
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
- {
- DEBUG_ERR_MSG("context->result is error [%d]", context->result);
- context->step = NET_NFC_LLCP_STEP_RETURN;
- }
-
- switch (context->step)
- {
- case NET_NFC_LLCP_STEP_01 :
- DEBUG_MSG("STEP [1]");
-
- if (bluetooth_register_callback(_net_nfc_service_llcp_process_bt_config_cb, context) >= BLUETOOTH_ERROR_NONE)
- {
- /* next step */
- context->step = NET_NFC_LLCP_STEP_02;
-
- if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED)
- {
- context->result = NET_NFC_OK;
- bluetooth_enable_adapter();
- }
- else
- {
- /* do next step */
- DEBUG_MSG("BT is enabled already, go next step");
-
- context->result = NET_NFC_OK;
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context);
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth_register_callback failed");
- context->result = NET_NFC_OPERATION_FAIL;
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_02 :
- {
- bluetooth_device_address_t address = { { 0, } };
- data_s temp = { NULL, 0 };
-
- DEBUG_MSG("STEP [2]");
-
- net_nfc_util_get_carrier_config_property(context->config, NET_NFC_BT_ATTRIBUTE_ADDRESS, (uint16_t *)&temp.length, &temp.buffer);
- if (temp.length == 6)
- {
- memcpy(address.addr, temp.buffer, MIN(sizeof(address.addr), temp.length));
-
- if (_net_nfc_service_llcp_handover_check_bond_device(&address) == true)
- {
- DEBUG_SERVER_MSG("already paired with [%02x:%02x:%02x:%02x:%02x:%02x]", address.addr[0], address.addr[1], address.addr[2], address.addr[3], address.addr[4], address.addr[5]);
-
- if (context->is_requester)
- {
- /* next step */
- context->step = NET_NFC_LLCP_STEP_03;
- }
- else
- {
- /* return */
- context->step = NET_NFC_LLCP_STEP_RETURN;
- }
-
- context->result = NET_NFC_OK;
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context);
- }
- else
- {
- bt_oob_data_t oob = { { 0 } , };
-
- if (net_nfc_service_llcp_handover_get_oob_data(context->config, &oob) == NET_NFC_OK)
- {
- /* set oob data */
- bluetooth_oob_add_remote_data(&address, &oob);
- }
-
- context->result = NET_NFC_OK;
-
- if (context->is_requester)
- {
- /* pair and send reponse */
- context->step = NET_NFC_LLCP_STEP_03;
-
- bluetooth_bond_device(&address);
- }
- else
- {
- /* return */
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context);
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth address is invalid. [%d] bytes", temp.length);
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- context->result = NET_NFC_OPERATION_FAIL;
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context);
- }
- }
- break;
-
- case NET_NFC_LLCP_STEP_03 :
- {
- data_s data = {NULL, 0};
-
- DEBUG_MSG("STEP [3]");
-
- context->step++;
-
- net_nfc_util_get_carrier_config_property(context->config, NET_NFC_BT_ATTRIBUTE_ADDRESS, (uint16_t *)&data.length, &data.buffer);
- if (data.length == 6)
- {
- /* send handover success message to client */
- _net_nfc_service_llcp_handover_send_response(context->llcp_state->client_fd, NET_NFC_OK, NET_NFC_CONN_HANDOVER_CARRIER_BT, &data);
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- context->result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("bluetooth address is invalid. [%d] bytes", data.length);
-
- context->step = NET_NFC_LLCP_STEP_RETURN;
- context->result = NET_NFC_OPERATION_FAIL;
- }
-
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_process_bt_config, (gpointer)context);
- }
- break;
-
- case NET_NFC_LLCP_STEP_RETURN :
- DEBUG_MSG("STEP return");
-
- /* unregister bluetooth callback */
- bluetooth_unregister_callback();
-
- g_idle_add((GSourceFunc)net_nfc_service_llcp_handover_return_to_step, (gpointer)context);
- break;
-
- default :
- break;
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return 0;
-}
-
-net_nfc_error_e net_nfc_service_llcp_handover_get_oob_data(net_nfc_carrier_config_s *config, bt_oob_data_t *oob)
-{
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
- data_s hash = { NULL, 0 };
- data_s randomizer = { NULL, 0 };
-
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (config == NULL || oob == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- memset(oob, 0, sizeof(bt_oob_data_t));
-
- if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, (uint16_t *)&hash.length, &hash.buffer)) == NET_NFC_OK)
- {
- if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, (uint16_t *)&randomizer.length, &randomizer.buffer)) == NET_NFC_OK)
- {
- if (hash.length == 16)
- {
- DEBUG_MSG("hash.length == 16");
-
- oob->hash_len = MIN(sizeof(oob->hash), hash.length);
- memcpy(oob->hash, hash.buffer, oob->hash_len);
- }
- else
- {
- DEBUG_ERR_MSG("hash.length error : [%d] bytes", hash.length);
- }
-
- if (randomizer.length == 16)
- {
- DEBUG_MSG("randomizer.length == 16");
-
- oob->randomizer_len = MIN(sizeof(oob->randomizer), randomizer.length);
- memcpy(oob->randomizer, randomizer.buffer, oob->randomizer_len);
- }
- else
- {
- DEBUG_ERR_MSG("randomizer.length error : [%d] bytes", randomizer.length);
- }
- }
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return result;
-}
-
-net_nfc_error_e net_nfc_service_llcp_handover_bt_change_data_order(net_nfc_carrier_config_s *config)
-{
- uint8_t *buffer = NULL;
- uint16_t len = 0;
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
-
- LOGD("[%s:%d] START", __func__, __LINE__);
-
- if (config == NULL)
- {
- return NET_NFC_NULL_PARAMETER;
- }
-
- if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_ADDRESS, &len, &buffer)) == NET_NFC_OK)
- {
- if (len == 6)
- {
- NET_NFC_REVERSE_ORDER_6_BYTES(buffer);
- }
- else
- {
- DEBUG_ERR_MSG("NET_NFC_BT_ATTRIBUTE_ADDRESS len error : [%d] bytes", len);
- }
- }
-
- if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_C, &len, &buffer)) == NET_NFC_OK)
- {
- if (len == 16)
- {
- NET_NFC_REVERSE_ORDER_16_BYTES(buffer);
- }
- else
- {
- DEBUG_ERR_MSG("NET_NFC_BT_ATTRIBUTE_OOB_HASH_C len error : [%d] bytes", len);
- }
- }
-
- if ((result = net_nfc_util_get_carrier_config_property(config, NET_NFC_BT_ATTRIBUTE_OOB_HASH_R, &len, &buffer)) == NET_NFC_OK)
- {
- if (len == 16)
- {
- NET_NFC_REVERSE_ORDER_16_BYTES(buffer);
- }
- else
- {
- DEBUG_ERR_MSG("NET_NFC_BT_ATTRIBUTE_OOB_HASH_R error : [%d] bytes", len);
- }
- }
-
- LOGD("[%s:%d] END", __func__, __LINE__);
-
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <pthread.h>
-#include <glib.h>
-#include <malloc.h>
-
-#include "vconf.h"
-#include "tapi_common.h"
-#include "ITapiSim.h"
-
-#include "net_nfc_controller_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_service_private.h"
-#include "net_nfc_app_util_private.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_server_dispatcher_private.h"
-#include "net_nfc_service_se_private.h"
-#include "net_nfc_server_context_private.h"
-
-/* define */
-
-/* static variable */
-static uint8_t g_se_prev_type = SECURE_ELEMENT_TYPE_INVALID;
-static uint8_t g_se_prev_mode = SECURE_ELEMENT_OFF_MODE;
-
-/* For ESE*/
-static net_nfc_se_setting_t g_se_setting;
-
-/* For UICC */
-static struct tapi_handle *uicc_handle = NULL;
-static bool net_nfc_service_check_sim_state(void);
-static void _uicc_transmit_apdu_cb(TapiHandle *handle, int result, void *data, void *user_data);
-static void _uicc_get_atr_cb(TapiHandle *handle, int result, void *data, void *user_data);
-static void _uicc_status_noti_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
-
-net_nfc_se_setting_t *net_nfc_service_se_get_se_setting()
-{
- return &g_se_setting;
-}
-
-net_nfc_target_handle_s *net_nfc_service_se_get_current_ese_handle()
-{
- return g_se_setting.current_ese_handle;
-}
-
-void net_nfc_service_se_set_current_ese_handle(net_nfc_target_handle_s *handle)
-{
- g_se_setting.current_ese_handle = handle;
-}
-
-uint8_t net_nfc_service_se_get_se_type()
-{
- return g_se_setting.type;
-}
-
-void net_nfc_service_se_set_se_type(uint8_t type)
-{
- g_se_setting.type = type;
-}
-
-uint8_t net_nfc_service_se_get_se_mode()
-{
- return g_se_setting.mode;
-}
-
-void net_nfc_service_se_set_se_mode(uint8_t mode)
-{
- g_se_setting.mode = mode;
-}
-
-net_nfc_error_e net_nfc_service_se_change_se(uint8_t type)
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- switch (type)
- {
- case SECURE_ELEMENT_TYPE_UICC :
- /*turn off ESE*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result);
-
- /*turn on UICC*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE, &result);
- if (result == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_UICC");
-
- net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_UICC);
- net_nfc_service_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE);
-
- if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_UICC) != 0)
- {
- DEBUG_ERR_MSG("vconf_set_int failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result);
- }
- break;
-
- case SECURE_ELEMENT_TYPE_ESE :
- /*turn off UICC*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result);
-
- /*turn on ESE*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE, &result);
- if (result == NET_NFC_OK)
- {
- DEBUG_SERVER_MSG("changed to SECURE_ELEMENT_TYPE_ESE");
-
- net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_ESE);
- net_nfc_service_se_set_se_mode(SECURE_ELEMENT_VIRTUAL_MODE);
-
- if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_ESE) != 0)
- {
- DEBUG_ERR_MSG("vconf_set_int failed");
- }
- }
- else
- {
- DEBUG_ERR_MSG("SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_VIRTUAL_MODE failed [%d]", result);
- }
- break;
-
- default :
- {
- net_nfc_error_e result_ese, result_uicc;
-
- net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_INVALID);
- net_nfc_service_se_set_se_mode(SECURE_ELEMENT_OFF_MODE);
-
- /*turn off ESE*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result_ese);
-
- /*turn off UICC*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result_uicc);
- if (result_ese != NET_NFC_INVALID_HANDLE && result_uicc != NET_NFC_INVALID_HANDLE)
- {
- DEBUG_SERVER_MSG("SE off all");
- if (vconf_set_int(VCONFKEY_NFC_SE_TYPE, VCONFKEY_NFC_SE_TYPE_NONE) != 0)
- {
- DEBUG_ERR_MSG("vconf_set_int failed");
- }
- result = NET_NFC_OK;
- }
- else
- {
- DEBUG_ERR_MSG("ALL OFF failed, ese [%d], uicc [%d]", result_ese, result_uicc);
- result = NET_NFC_INVALID_HANDLE;
- }
- }
- break;
- }
-
- return result;
-}
-
-void net_nfc_service_se_detected(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_target_detected_t *detail_msg = (net_nfc_request_target_detected_t *)(msg);
- net_nfc_target_handle_s *handle = NULL;
- net_nfc_error_e state = NET_NFC_OK;
- net_nfc_response_open_internal_se_t resp = { 0 };
-
- if (detail_msg == NULL)
- {
- return;
- }
-
- handle = detail_msg->handle;
- g_se_setting.current_ese_handle = handle;
-
- DEBUG_SERVER_MSG("trying to connect to ESE = [0x%p]", handle);
-
- if (!net_nfc_controller_connect(handle, &state))
- {
- DEBUG_SERVER_MSG("connect failed = [%d]", state);
- resp.result = state;
- }
-
-#ifdef BROADCAST_MESSAGE
- net_nfc_server_set_server_state(NET_NFC_SE_CONNECTED);
-#endif
-
- resp.handle = handle;
- resp.trans_param = g_se_setting.open_request_trans_param;
- resp.se_type = SECURE_ELEMENT_TYPE_ESE;
-
- DEBUG_SERVER_MSG("trans param = [%p]", resp.trans_param);
-
- net_nfc_send_response_msg(detail_msg->client_fd, NET_NFC_MESSAGE_OPEN_INTERNAL_SE,
- &resp, sizeof(net_nfc_response_open_internal_se_t), NULL);
-
- g_se_setting.open_request_trans_param = NULL;
-}
-
-net_nfc_error_e net_nfc_service_se_close_ese()
-{
- net_nfc_error_e result = NET_NFC_OK;
-
- if (g_se_setting.current_ese_handle != NULL)
- {
- if (net_nfc_controller_secure_element_close(g_se_setting.current_ese_handle, &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
- net_nfc_service_se_set_current_ese_handle(NULL);
- }
-
- return result;
-}
-
-bool net_nfc_service_tapi_init(void)
-{
- char **cpList = NULL;
-
- DEBUG_SERVER_MSG("tapi init");
-
- cpList = tel_get_cp_name_list();
-
- uicc_handle = tel_init(cpList[0]);
- if (uicc_handle == NULL)
- {
- int error;
-
- error = tel_register_noti_event(uicc_handle, TAPI_NOTI_SIM_STATUS, _uicc_status_noti_cb, NULL);
- }
- else
- {
- DEBUG_SERVER_MSG("tel_init() failed");
- return false;
- }
-
- DEBUG_SERVER_MSG("tel_init() is success");
-
- return net_nfc_service_check_sim_state();
-}
-
-void net_nfc_service_tapi_deinit(void)
-{
- DEBUG_SERVER_MSG("deinit tapi");
-
- tel_deregister_noti_event(uicc_handle, TAPI_NOTI_SIM_STATUS);
-
- tel_deinit(uicc_handle);
-}
-
-bool net_nfc_service_transfer_apdu(int client_fd, data_s *apdu, void *trans_param)
-{
- net_nfc_request_msg_t *param = NULL;
- TelSimApdu_t apdu_data = { 0 };
- int result;
-
- DEBUG_SERVER_MSG("tranfer apdu");
-
- if (apdu == NULL)
- return false;
-
- apdu_data.apdu = apdu->buffer;
- apdu_data.apdu_len = apdu->length;
-
- /* make param */
- _net_nfc_util_alloc_mem(param, sizeof(net_nfc_request_msg_t));
- if (param != NULL)
- {
- param->client_fd = client_fd;
- param->user_param = (uint32_t)trans_param;
-
- result = tel_req_sim_apdu(uicc_handle, &apdu_data, _uicc_transmit_apdu_cb, param);
- if (result == 0)
- {
- DEBUG_SERVER_MSG("sim apdu request is success");
- }
- else
- {
- DEBUG_ERR_MSG("request sim apdu is failed with error = [%d]", result);
- return false;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- return false;
- }
-
- return true;
-}
-
-bool net_nfc_service_request_atr(int client_fd, void *trans_param)
-{
- int result;
- net_nfc_request_msg_t *param = NULL;
-
- /* make param */
- _net_nfc_util_alloc_mem(param, sizeof(net_nfc_request_msg_t));
- if (param != NULL)
- {
- param->client_fd = client_fd;
- param->user_param = (uint32_t)trans_param;
-
- result = tel_req_sim_atr(uicc_handle, _uicc_get_atr_cb, param);
- if (result == 0)
- {
- DEBUG_SERVER_MSG("request is success");
- }
- else
- {
- DEBUG_SERVER_MSG("failed to request ATR = [%d]", result);
- return false;
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_manager_util_alloc_mem failed");
- return false;
- }
-
- return true;
-}
-
-static bool net_nfc_service_check_sim_state(void)
-{
- TelSimCardStatus_t state = (TelSimCardStatus_t)0;
- int b_card_changed = 0;
- int error;
-
- DEBUG_SERVER_MSG("check sim state");
-
- error = tel_get_sim_init_info(uicc_handle, &state, &b_card_changed);
-
- DEBUG_SERVER_MSG("current sim init state = [%d]", state);
-
- if (error != 0)
- {
- DEBUG_SERVER_MSG("error = [%d]", error);
- return false;
- }
- else if (state == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || state == TAPI_SIM_STATUS_SIM_INITIALIZING)
- {
- DEBUG_SERVER_MSG("sim is initialized");
- }
- else
- {
- DEBUG_SERVER_MSG("sim is not initialized");
- return false;
- }
-
- return true;
-}
-
-void _uicc_transmit_apdu_cb(TapiHandle *handle, int result, void *data, void *user_data)
-{
- TelSimApduResp_t *apdu = (TelSimApduResp_t *)data;
- net_nfc_response_send_apdu_t resp = { 0 };
- net_nfc_request_msg_t *param = (net_nfc_request_msg_t *)user_data;
-
- DEBUG_SERVER_MSG("_uicc_transmit_apdu_cb");
-
- if (result == 0)
- {
- resp.result = NET_NFC_OK;
- }
- else
- {
- resp.result = NET_NFC_OPERATION_FAIL;
- }
-
- resp.trans_param = (void *)param->user_param;
-
- if (apdu != NULL && apdu->apdu_resp_len > 0)
- {
- resp.data.length = apdu->apdu_resp_len;
-
- DEBUG_MSG("send response send apdu msg");
- net_nfc_send_response_msg(param->client_fd, NET_NFC_MESSAGE_SEND_APDU_SE,
- (void *)&resp, sizeof(net_nfc_response_send_apdu_t), apdu->apdu_resp, apdu->apdu_resp_len, NULL);
- }
- else
- {
- DEBUG_MSG("send response send apdu msg");
- net_nfc_send_response_msg(param->client_fd, NET_NFC_MESSAGE_SEND_APDU_SE,
- (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL);
- }
-
- _net_nfc_util_free_mem(param);
-}
-
-void _uicc_get_atr_cb(TapiHandle *handle, int result, void *data, void *user_data)
-{
- net_nfc_request_msg_t *param = (net_nfc_request_msg_t *)user_data;
-
- /* TODO : response message */
-
- DEBUG_SERVER_MSG("_uicc_get_atr_cb");
-
- _net_nfc_util_free_mem(param);
-}
-
-void _uicc_status_noti_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
-{
- TelSimCardStatus_t *status = (TelSimCardStatus_t *)data;
-
- /* TODO : */
- DEBUG_SERVER_MSG("_uicc_status_noti_cb");
-
- switch (*status)
- {
- case TAPI_SIM_STATUS_SIM_INIT_COMPLETED :
- DEBUG_SERVER_MSG("TAPI_SIM_STATUS_SIM_INIT_COMPLETED");
- break;
-
- case TAPI_SIM_STATUS_CARD_REMOVED :
- DEBUG_SERVER_MSG("TAPI_SIM_STATUS_CARD_REMOVED");
- break;
-
- default :
- DEBUG_SERVER_MSG("unknown status [%d]", *status);
- break;
- }
-}
-
-bool net_nfc_service_se_transaction_receive(net_nfc_request_msg_t* msg)
-{
- bool res = true;
- net_nfc_request_se_event_t *se_event = (net_nfc_request_se_event_t *)msg;
-
- if (se_event->request_type == NET_NFC_MESSAGE_SE_START_TRANSACTION)
- {
- DEBUG_SERVER_MSG("launch se app");
-
- net_nfc_app_util_launch_se_transaction_app(se_event->aid.buffer,
- se_event->aid.length, se_event->param.buffer, se_event->param.length);
-
- DEBUG_SERVER_MSG("launch se app end");
- }
-
- return res;
-}
-
-void net_nfc_service_se_send_apdu(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_send_apdu_t *detail = (net_nfc_request_send_apdu_t *)msg;
-
- if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE)
- {
- data_s apdu_data = { NULL, 0 };
-
- if (net_nfc_util_duplicate_data(&apdu_data, &detail->data) == false)
- return;
-
- net_nfc_service_transfer_apdu(msg->client_fd, &apdu_data, detail->trans_param);
-
- net_nfc_util_free_data(&apdu_data);
- }
- else if (detail->handle == net_nfc_service_se_get_current_ese_handle())
- {
- bool success;
- data_s command;
- data_s *response = NULL;
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
-
- if (net_nfc_util_duplicate_data(&command, &detail->data) == false)
- {
- DEBUG_ERR_MSG("alloc failed");
- return;
- }
-
- if ((success = net_nfc_controller_secure_element_send_apdu(detail->handle, &command, &response, &result)) == true)
- {
- if (response != NULL)
- {
- DEBUG_SERVER_MSG("transceive data received, len [%d]", response->length);
- }
- }
- else
- {
- DEBUG_ERR_MSG("transceive failed = [%d]", result);
- }
- net_nfc_util_free_data(&command);
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_send_apdu_t resp = { 0, };
-
- DEBUG_SERVER_MSG("send response send_apdu");
-
- resp.length = sizeof(net_nfc_response_send_apdu_t);
- resp.flags = detail->flags;
- resp.user_param = detail->user_param;
- resp.trans_param = detail->trans_param;
- resp.result = result;
-
- if (response != NULL)
- {
- resp.data.length = response->length;
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_send_apdu_t),
- response->buffer, response->length, NULL);
- }
- else
- {
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL);
- }
- }
- }
- else
- {
- DEBUG_SERVER_MSG("invalid se handle");
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_send_apdu_t resp = { 0 };
-
- resp.length = sizeof(net_nfc_response_send_apdu_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
- resp.result = NET_NFC_INVALID_PARAM;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_send_apdu_t), NULL);
- }
- }
-}
-
-void net_nfc_service_se_get_atr(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_get_atr_t *detail = (net_nfc_request_get_atr_t *)msg;
-
- if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE)
- {
- net_nfc_service_request_atr(msg->client_fd, (void *)detail->user_param);
- }
- else if (detail->handle == net_nfc_service_se_get_current_ese_handle())
- {
- net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR;
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_get_atr_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_get_atr_t);
- resp.flags = detail->flags;
- resp.user_param = detail->user_param;
- resp.result = result;
-
- DEBUG_SERVER_MSG("send response send apdu msg");
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_get_atr_t), NULL);
- }
- }
- else
- {
- DEBUG_SERVER_MSG("invalid se handle");
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_get_atr_t resp = { 0 };
-
- resp.length = sizeof(net_nfc_response_get_atr_t);
- resp.flags = detail->flags;
- resp.user_param = detail->user_param;
- resp.result = NET_NFC_INVALID_PARAM;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_get_atr_t), NULL);
- }
- }
-}
-
-void net_nfc_service_se_close_se(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_close_internal_se_t *detail = (net_nfc_request_close_internal_se_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
-
- if (detail->handle == (net_nfc_target_handle_s *)UICC_TARGET_HANDLE)
- {
- /*deinit TAPI*/
- DEBUG_SERVER_MSG("UICC is current secure element");
- net_nfc_service_tapi_deinit();
-
- }
- else if (detail->handle == net_nfc_service_se_get_current_ese_handle())
- {
- result = net_nfc_service_se_close_ese();
-#ifdef BROADCAST_MESSAGE
- net_nfc_server_unset_server_state(NET_NFC_SE_CONNECTED);
-#endif
- }
- else
- {
- DEBUG_ERR_MSG("invalid se handle received handle = [0x%p] and current handle = [0x%p]",
- detail->handle, net_nfc_service_se_get_current_ese_handle());
- }
-
- if ((g_se_prev_type != net_nfc_service_se_get_se_type()) || (g_se_prev_mode != net_nfc_service_se_get_se_mode()))
- {
- /*return back se mode*/
- net_nfc_controller_set_secure_element_mode(g_se_prev_type, g_se_prev_mode, &result);
-
- net_nfc_service_se_set_se_type(g_se_prev_type);
- net_nfc_service_se_set_se_mode(g_se_prev_mode);
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_close_internal_se_t resp = { 0 };
-
- resp.length = sizeof(net_nfc_response_close_internal_se_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
- resp.result = result;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_close_internal_se_t), NULL);
- }
-
-}
-
-void net_nfc_service_se_open_se(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_open_internal_se_t *detail = (net_nfc_request_open_internal_se_t *)msg;
- net_nfc_target_handle_s *handle = NULL;
- net_nfc_error_e result = NET_NFC_OK;
-
- g_se_prev_type = net_nfc_service_se_get_se_type();
- g_se_prev_mode = net_nfc_service_se_get_se_mode();
-
- if (detail->se_type == SECURE_ELEMENT_TYPE_UICC)
- {
- /*off ESE*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE, SECURE_ELEMENT_OFF_MODE, &result);
-
- /*Off UICC. UICC SHOULD not be detected by external reader when being communicated in internal process*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result);
-
- net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_UICC);
- net_nfc_service_se_set_se_mode(SECURE_ELEMENT_OFF_MODE);
-
- /*Init tapi api and return back response*/
- if (net_nfc_service_tapi_init() != true)
- {
- net_nfc_service_tapi_deinit();
- result = NET_NFC_INVALID_STATE;
- handle = NULL;
- }
- else
- {
- result = NET_NFC_OK;
- handle = (net_nfc_target_handle_s *)UICC_TARGET_HANDLE;
- }
- }
- else if (detail->se_type == SECURE_ELEMENT_TYPE_ESE)
- {
- /*off UICC*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC, SECURE_ELEMENT_OFF_MODE, &result);
-
- if (net_nfc_controller_secure_element_open(SECURE_ELEMENT_TYPE_ESE, &handle, &result) == true)
- {
- net_nfc_service_se_set_se_type(SECURE_ELEMENT_TYPE_ESE);
- net_nfc_service_se_set_se_mode(SECURE_ELEMENT_WIRED_MODE);
-
- net_nfc_service_se_get_se_setting()->open_request_trans_param = detail->trans_param;
- net_nfc_service_se_set_current_ese_handle(handle);
-
- DEBUG_ERR_MSG("handle [%p]", handle);
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_secure_element_open failed [%d]", result);
- }
- }
- else
- {
- result = NET_NFC_INVALID_STATE;
- handle = NULL;
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_open_internal_se_t resp = { 0 };
-
- resp.length = sizeof(net_nfc_response_open_internal_se_t);
- resp.flags = detail->flags;
- resp.user_param = detail->user_param;
- resp.trans_param = detail->trans_param;
- resp.result = result;
- resp.se_type = detail->se_type;
- resp.handle = handle;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_open_internal_se_t), NULL);
- }
-}
-
-void net_nfc_service_se_set_se(net_nfc_request_msg_t *msg)
-{
-#if 1
- net_nfc_request_set_se_t *detail = (net_nfc_request_set_se_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
- bool isTypeChange = false;
-
- if (detail->se_type != net_nfc_service_se_get_se_type())
- {
- result = net_nfc_service_se_change_se(detail->se_type);
- isTypeChange = true;
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_set_se_t resp = { 0 };
-
- resp.length = sizeof(net_nfc_response_set_se_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
- resp.se_type = detail->se_type;
- resp.result = result;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_set_se_t), NULL);
- }
-
- if (isTypeChange)
- {
- net_nfc_response_notify_t noti_se = { 0, };
-
- net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_SE_TYPE_CHANGED,
- (void *)¬i_se, sizeof(net_nfc_response_notify_t), NULL);
- }
-
-#else
- net_nfc_request_set_se_t *detail = (net_nfc_request_set_se_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
- int mode;
-
- mode = (int)detail->se_type;
-
- if (mode == NET_NFC_SE_CMD_UICC_ON)
- {
- /*turn on UICC*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_VIRTUAL_MODE, &result);
-
- /*turn off ESE*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE,
- SECURE_ELEMENT_OFF_MODE, &result);
- }
- else if (mode == NET_NFC_SE_CMD_ESE_ON)
- {
- /*turn off UICC*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_OFF_MODE, &result);
-
- /*turn on ESE*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE,
- SECURE_ELEMENT_VIRTUAL_MODE, &result);
- }
- else if (mode == NET_NFC_SE_CMD_ALL_OFF)
- {
- /*turn off both*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_OFF_MODE, &result);
-
- /*turn on ESE*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE,
- SECURE_ELEMENT_OFF_MODE, &result);
- }
- else
- {
- /*turn off both*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_UICC,
- SECURE_ELEMENT_VIRTUAL_MODE, &result);
-
- /*turn on ESE*/
- net_nfc_controller_set_secure_element_mode(SECURE_ELEMENT_TYPE_ESE,
- SECURE_ELEMENT_VIRTUAL_MODE, &result);
- }
-#endif
-}
-
-void net_nfc_service_se_get_se(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_get_se_t *detail = (net_nfc_request_get_se_t *)msg;
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_get_se_t resp = { 0 };
-
- resp.length = sizeof(net_nfc_request_get_se_t);
- resp.flags = detail->flags;
- resp.trans_param = detail->trans_param;
- resp.result = NET_NFC_OK;
- resp.se_type = net_nfc_service_se_get_se_type();
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_get_se_t), NULL);
- }
-}
-
-void net_nfc_service_se_cleanup()
-{
- DEBUG_SERVER_MSG("client is terminated abnormally");
-
- if (g_se_prev_type == SECURE_ELEMENT_TYPE_ESE)
- {
- net_nfc_error_e result = NET_NFC_OK;
- net_nfc_target_handle_s *ese_handle = net_nfc_service_se_get_current_ese_handle();
-
- if (ese_handle != NULL)
- {
- DEBUG_SERVER_MSG("ese_handle was not freed and disconnected");
-
- net_nfc_service_se_close_ese();
-#ifdef BROADCAST_MESSAGE
- net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE);
-#endif
- }
-
- if ((g_se_prev_type != net_nfc_service_se_get_se_type()) || (g_se_prev_mode != net_nfc_service_se_get_se_mode()))
- {
- net_nfc_controller_set_secure_element_mode(g_se_prev_type, g_se_prev_mode, &result);
-
- net_nfc_service_se_set_se_type(g_se_prev_type);
- net_nfc_service_se_set_se_mode(g_se_prev_mode);
- }
- }
- else if (g_se_prev_type == SECURE_ELEMENT_TYPE_UICC)
- {
- net_nfc_service_tapi_deinit();
- }
- else
- {
- DEBUG_SERVER_MSG("SE type is not valid");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <pthread.h>
-#include <malloc.h>
-#include <unistd.h>
-
-#include "net_nfc_controller_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_typedef.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_service_private.h"
-#include "net_nfc_app_util_private.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_server_dispatcher_private.h"
-#include "net_nfc_manager_util_private.h"
-#include "net_nfc_server_context_private.h"
-
-/* define */
-
-/* static variable */
-
-/* static callback function */
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-void net_nfc_service_watch_dog(net_nfc_request_msg_t* req_msg)
-{
- net_nfc_request_watch_dog_t *detail_msg = NULL;
- net_nfc_error_e result = NET_NFC_OK;
- bool isPresentTarget = true;
-
- if (req_msg == NULL)
- {
- return;
- }
-
- detail_msg = (net_nfc_request_watch_dog_t *)req_msg;
-
- //DEBUG_SERVER_MSG("connection type = [%d]", detail_msg->handle->connection_type);
-
- /* IMPORTANT, TEMPORARY : switching context to another thread for give CPU time */
- usleep(10000);
-
- if ((detail_msg->handle->connection_type == NET_NFC_P2P_CONNECTION_TARGET) || (detail_msg->handle->connection_type == NET_NFC_TAG_CONNECTION))
- {
- isPresentTarget = net_nfc_controller_check_target_presence(detail_msg->handle, &result);
- }
- else
- {
- isPresentTarget = false;
- }
-
- if (isPresentTarget == true)
- {
- /* put message again */
- net_nfc_dispatcher_queue_push(req_msg);
- }
- else
- {
- //DEBUG_SERVER_MSG("try to disconnect target = [%d]", detail_msg->handle);
-
- if ((NET_NFC_NOT_INITIALIZED != result) && (NET_NFC_INVALID_HANDLE != result))
- {
- if (net_nfc_controller_disconnect(detail_msg->handle, &result) == false)
- {
-
- DEBUG_SERVER_MSG("try to disconnect result = [%d]", result);
- net_nfc_controller_exception_handler();
- }
- }
-#ifdef BROADCAST_MESSAGE
- net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE);
-#endif
-
- {
- net_nfc_response_target_detached_t target_detached = { 0, };
- memset(&target_detached, 0x00, sizeof(net_nfc_response_target_detached_t));
-
- target_detached.devType = detail_msg->devType;
- target_detached.handle = detail_msg->handle;
-
- net_nfc_broadcast_response_msg(NET_NFC_MESSAGE_TAG_DETACHED, (void*)&target_detached, sizeof(net_nfc_response_target_detached_t), NULL);
- }
-
- _net_nfc_util_free_mem(req_msg);
- }
-}
-
-void net_nfc_service_clean_tag_context(net_nfc_request_target_detected_t* stand_alone, net_nfc_error_e result)
-{
- if (result == NET_NFC_OK)
- {
- bool isPresentTarget = true;
- net_nfc_error_e result = NET_NFC_OK;
-
- while (isPresentTarget)
- {
- isPresentTarget = net_nfc_controller_check_target_presence(stand_alone->handle, &result);
- }
-
- if (net_nfc_controller_disconnect(stand_alone->handle, &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
- }
- else
- {
- net_nfc_error_e result = NET_NFC_OK;
-
- if (result != NET_NFC_TARGET_IS_MOVED_AWAY && result != NET_NFC_OPERATION_FAIL)
- {
- bool isPresentTarget = true;
-
- while (isPresentTarget)
- {
- isPresentTarget = net_nfc_controller_check_target_presence(stand_alone->handle, &result);
- }
- }
-
- DEBUG_SERVER_MSG("try to disconnect target = [%d]", stand_alone->handle->connection_id);
-
- if (net_nfc_controller_disconnect(stand_alone->handle, &result) == false)
- {
- net_nfc_controller_exception_handler();
- }
- }
-
-#ifdef BROADCAST_MESSAGE
- net_nfc_server_set_server_state(NET_NFC_SERVER_IDLE);
-#endif
-}
-
-#ifndef BROADCAST_MESSAGE
-data_s* net_nfc_service_tag_process(net_nfc_target_handle_s* handle, int devType, net_nfc_error_e* result)
-{
- net_nfc_error_e status = NET_NFC_OK;
- data_s* recv_data = NULL;
- *result = NET_NFC_OK;
-
- DEBUG_SERVER_MSG("trying to connect to tag = [0x%p]", handle);
-
- if (!net_nfc_controller_connect (handle, &status))
- {
- DEBUG_SERVER_MSG("connect failed");
- *result = status;
- return NULL;
- }
-
-#ifdef BROADCAST_MESSAGE
- net_nfc_server_set_server_state(NET_NFC_TAG_CONNECTED);
-#endif
-
- DEBUG_SERVER_MSG("read ndef from tag");
-
- if(net_nfc_controller_read_ndef (handle, &recv_data, &status) == true)
- {
- return recv_data;
- }
- else
- {
- DEBUG_SERVER_MSG("can not read card");
- *result = status;
- return NULL;
- }
-
-}
-#endif
-
-void net_nfc_service_tag_make_readonly(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_make_read_only_ndef_t *detail = (net_nfc_request_make_read_only_ndef_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
-
- if (net_nfc_server_is_target_connected(detail->handle))
- {
- net_nfc_controller_make_read_only_ndef(detail->handle, &result);
- }
- else
- {
- result = NET_NFC_TARGET_IS_MOVED_AWAY;
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_make_read_only_ndef_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_make_read_only_ndef_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.trans_param = detail->trans_param;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_write_ndef_t), NULL);
- }
-}
-
-void net_nfc_service_tag_read_ndef(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_read_ndef_t *detail = (net_nfc_request_read_ndef_t *)msg;
- net_nfc_error_e result = NET_NFC_TARGET_IS_MOVED_AWAY;
- data_s *data = NULL;
-
- if (net_nfc_server_is_target_connected(detail->handle))
- {
- net_nfc_controller_read_ndef(detail->handle, &data, &result);
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_read_ndef_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_read_ndef_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.trans_param = detail->trans_param;
-
- if (data != NULL)
- {
- resp.data.length = data->length;
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_read_ndef_t),
- data->buffer, data->length, NULL);
- }
- else
- {
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_read_ndef_t), NULL);
- }
- }
-
- if (data != NULL)
- {
- net_nfc_util_free_data(data);
- _net_nfc_util_free_mem(data);
- }
-}
-
-void net_nfc_service_tag_write_ndef(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_write_ndef_t *detail = (net_nfc_request_write_ndef_t *)msg;
- net_nfc_error_e result = NET_NFC_TARGET_IS_MOVED_AWAY;
-
- if (net_nfc_server_is_target_connected(detail->handle))
- {
- data_s data = { NULL, 0 };
-
- if (net_nfc_util_duplicate_data(&data, &detail->data) == true)
- {
- net_nfc_controller_write_ndef(detail->handle, &data, &result);
-
- net_nfc_util_free_data(&data);
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_write_ndef_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_write_ndef_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.trans_param = detail->trans_param;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_write_ndef_t), NULL);
- }
-}
-
-void net_nfc_service_tag_format_ndef(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_format_ndef_t *detail = (net_nfc_request_format_ndef_t *)msg;
- net_nfc_error_e result = NET_NFC_TARGET_IS_MOVED_AWAY;
-
- if (net_nfc_server_is_target_connected(detail->handle))
- {
- data_s data = { NULL, 0 };
-
- if (net_nfc_util_duplicate_data(&data, &detail->key) == true)
- {
- net_nfc_controller_format_ndef(detail->handle, &data, &result);
- net_nfc_util_free_data(&data);
- }
- else
- {
- result = NET_NFC_ALLOC_FAIL;
- }
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_format_ndef_t resp = { 0 };
-
- resp.length = sizeof(net_nfc_response_format_ndef_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.trans_param = detail->trans_param;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_format_ndef_t), NULL);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "net_nfc_typedef.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_server_ipc_private.h"
-#include "net_nfc_controller_private.h"
-#include "net_nfc_service_test_private.h"
-#include "net_nfc_server_context_private.h"
-
-void net_nfc_service_test_sim_test(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_test_t *detail = (net_nfc_request_test_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
-
- if (net_nfc_controller_sim_test(&result) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_sim_test Result [SUCCESS]");
- }
- else
- {
- DEBUG_SERVER_MSG("net_nfc_controller_sim_test Result [ERROR1]");
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_test_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_test_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.trans_param = detail->trans_param;
-
- DEBUG_SERVER_MSG("SEND RESPONSE!!");
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_test_t), NULL);
- }
-}
-
-void net_nfc_service_test_get_firmware_version(net_nfc_request_msg_t *msg)
-{
- net_nfc_error_e result = NET_NFC_OK;
- data_s *data = NULL;
-
- if (net_nfc_controller_get_firmware_version(&data, &result) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_update_firmware Result [SUCCESS]");
-
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_update_firmware Result [ERROR3]");
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_firmware_version_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_firmware_version_t);
- resp.flags = msg->flags;
- resp.result = result;
-
- if (data != NULL)
- {
- resp.data.length = data->length;
-
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_firmware_version_t),
- (void *)data->buffer, resp.data.length, NULL);
- }
- else
- {
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_firmware_version_t), NULL);
- }
- }
-
- if (data != NULL)
- {
- net_nfc_util_free_data(data);
- _net_nfc_util_free_mem(data);
- }
-}
-
-void net_nfc_service_test_prbs_test(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_test_t *detail = (net_nfc_request_test_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
- uint32_t local_tech = 0;
- uint32_t local_rate = 0;
-
- local_tech = detail->tech;
- local_rate = detail->rate;
-
- DEBUG_SERVER_MSG("local_tech [%d]\n", local_tech);
- DEBUG_SERVER_MSG("local_rate [%d]\n", local_rate);
-
- if (net_nfc_controller_prbs_test(&result, local_tech, local_rate) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_prbs_test Result [SUCCESS]");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_prbs_test Result [ERROR3]");
- }
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_test_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_test_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.trans_param = detail->trans_param;
-
- DEBUG_SERVER_MSG("SEND RESPONSE!!");
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_test_t), NULL);
- }
-}
-
-void net_nfc_service_test_set_eedata(net_nfc_request_msg_t *msg)
-{
- net_nfc_request_eedata_register_t *detail = (net_nfc_request_eedata_register_t *)msg;
- net_nfc_error_e result = NET_NFC_OK;
- uint32_t local_mode = 0;
- uint32_t local_reg_id = 0;
- data_s data = { NULL, 0 };
-
- local_mode = detail->mode;
- local_reg_id = detail->reg_id;
-
- DEBUG_SERVER_MSG("local_mode [%d]\n", local_mode);
- DEBUG_SERVER_MSG("local_reg_id [%d]\n", local_reg_id);
-
- if (net_nfc_util_duplicate_data(&data, &detail->data) == true)
- {
- if (net_nfc_controller_eedata_register_set(&result, local_mode,
- local_reg_id, &data) == true)
- {
- DEBUG_SERVER_MSG("net_nfc_controller_eedata_register_set Result [SUCCESS]");
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_controller_eedata_register_set Result [ERROR3]");
- }
- net_nfc_util_free_data(&data);
-
- if (net_nfc_server_check_client_is_running(msg->client_fd))
- {
- net_nfc_response_test_t resp = { 0, };
-
- resp.length = sizeof(net_nfc_response_test_t);
- resp.flags = detail->flags;
- resp.result = result;
- resp.trans_param = detail->trans_param;
-
- DEBUG_SERVER_MSG("SEND RESPONSE!!");
- net_nfc_send_response_msg(msg->client_fd, msg->request_type,
- (void *)&resp, sizeof(net_nfc_response_test_t), NULL);
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <vconf.h>
-#include <glib.h>
-#include <string.h>
-#include "net_nfc_typedef_private.h"
-#include "net_nfc_debug_private.h"
-#include "net_nfc_controller_private.h"
-#include "net_nfc_util_private.h"
-#include "net_nfc_server_dispatcher_private.h"
-#include "net_nfc_app_util_private.h"
-#include "aul.h"
-
-
-
-/////////////////////////////////////////////////////////////////////////
-
-static void net_nfc_service_airplane_mode_cb(keynode_t* key, void* data)
-{
- int flight_mode = 0;
- int nfc_state, sbeam_state, predefined_state = 0;
- static gboolean powered_off_by_flightmode = FALSE;
- int result;
-
- if ((result= vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode)) == 0)
- {
- DEBUG_SERVER_MSG("vconf_get_bool success \n");
- }
- else
- {
- DEBUG_ERR_MSG("vconf_get_bool failed \n");
- }
- if ((result= vconf_get_bool(VCONFKEY_NFC_STATE, &nfc_state)) == 0)
- {
- DEBUG_SERVER_MSG("vconf_get_bool success \n");
- }
- else
- {
- DEBUG_ERR_MSG("vconf_get_bool failed \n");
- }
- if ((result= vconf_get_bool(VCONFKEY_NFC_SBEAM, &sbeam_state)) == 0)
- {
- DEBUG_SERVER_MSG("vconf_get_bool success \n");
- }
- else
- {
- DEBUG_ERR_MSG("vconf_get_bool failed \n");
- }
- if ((result= vconf_get_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, &predefined_state)) == 0)
- {
- DEBUG_SERVER_MSG("vconf_get_bool success \n");
- }
- else
- {
- DEBUG_ERR_MSG("vconf_get_bool failed \n");
- }
-
- DEBUG_SERVER_MSG("flight mode %s \n", flight_mode > 0 ? "ON" : "OFF");
- DEBUG_SERVER_MSG("nfc_state %d, sbeam_state %d, predefined_state %d NFC was off by flight mode %s \n",
- nfc_state, sbeam_state, predefined_state, powered_off_by_flightmode == TRUE ? "Yes" : "No");
-
- if (flight_mode > 0) /* turn flight mode on */
- {
- /* flight mode enabled */
- if (nfc_state == VCONFKEY_NFC_STATE_OFF)
- return;
-
- DEBUG_SERVER_MSG("Turning NFC off \n");
-
- /* nfc off */
- net_nfc_request_msg_t *req_msg = NULL;
-
- _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));
- if (req_msg == NULL)
- return;
-
- req_msg->length = sizeof(net_nfc_request_msg_t);
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_DEINIT;
-
- net_nfc_dispatcher_queue_push(req_msg);
-
- /* set internal flag */
- powered_off_by_flightmode = TRUE;
-
- /* sbeam off */
- if ((result = vconf_set_bool(VCONFKEY_NFC_SBEAM, FALSE)) == 0)
- {
- DEBUG_SERVER_MSG("vconf_set_bool success \n");
- }
- else
- {
- DEBUG_ERR_MSG("vconf_set_bool failed \n");
- }
-
- /* predefined item off */
- if ((result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, FALSE)) == 0)
- {
- DEBUG_SERVER_MSG("vconf_set_bool success \n");
- }
- else
- {
- DEBUG_ERR_MSG("vconf_set_bool failed \n");
- }
- }
- else if (flight_mode == 0) /* turn flight mode off */
- {
- /* flight mode disabled */
- if (nfc_state > VCONFKEY_NFC_STATE_OFF)
- return;
-
- if (powered_off_by_flightmode != TRUE)
- return;
-
- DEBUG_SERVER_MSG("Turning NFC on \n");
-
- /* nfc on */
- net_nfc_request_msg_t *req_msg = NULL;
-
- _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));
- if (req_msg == NULL)
- return;
-
- req_msg->length = sizeof(net_nfc_request_msg_t);
- req_msg->request_type = NET_NFC_MESSAGE_SERVICE_INIT;
-
- net_nfc_dispatcher_queue_push(req_msg);
-
- /* unset internal flag */
- powered_off_by_flightmode = FALSE;
-
- /* sbeam on */
- if ((result = vconf_set_bool(VCONFKEY_NFC_SBEAM, TRUE)) == 0)
- {
- DEBUG_SERVER_MSG("vconf_set_bool success \n");
- }
- else
- {
- DEBUG_ERR_MSG("vconf_set_bool failed \n");
- }
-
- /* predefined item on */
- if ((result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, TRUE)) == 0)
- {
- DEBUG_SERVER_MSG("vconf_set_bool success \n");
- }
- else
- {
- DEBUG_ERR_MSG("vconf_set_bool failed \n");
- }
- }
- else
- {
- DEBUG_SERVER_MSG("Invalid Vconf value \n");
- }
-}
-
-
-
-void net_nfc_service_vconf_register_notify_listener()
-{
- vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, net_nfc_service_airplane_mode_cb, NULL);
-}
-
-void net_nfc_service_vconf_unregister_notify_listener()
-{
- vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, net_nfc_service_airplane_mode_cb);
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns="http://tizen.org/ns/packages"
+ package="nfc-manager"
+ version="0.1.0"
+ install-location="internal-only"
+ type="rpm">
+ <label>NFC Manager</label>
+ <author email="email" href="www.samsung.com">name</author>
+ <description>NFC manager</description>
+ <ui-application appid="nfc-manager"
+ exec="/usr/bin/nfc-manager-daemon"
+ nodisplay="true"
+ multiple="false"
+ type="capp"
+ taskmanage="false"
+ mainapp="true">
+ <label>NFC Manager</label>
+ </ui-application>
+</manifest>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<node name="/org/tizen/nfc_service">
- <interface name="org.tizen.nfc_service">
- <method name="Launch">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="nfc_service_launch"/>
- <arg type="u" name="pid" direction="in"/>
- <arg type="u" name="result_val" direction="out"/>
- </method>
-
- <method name="Terminate">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="nfc_service_terminate"/>
- <arg type="u" name="result_val" direction="out"/>
- </method>
-
- </interface>
-</node>
[D-BUS Service]
-Name=org.tizen.nfc_service
+Name=org.tizen.NetNfcService
Exec=/usr/bin/nfc-manager-daemon
-User=root
SET(NDEF_TOOL "ndef-tool")
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../src/commonlib/include)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../src/clientlib/include)
+include_directories(${CMAKE_SOURCE_DIR}/src/commonlib)
+include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
+include_directories(${CMAKE_SOURCE_DIR}/src/clientlib/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ TOOL_SRC)
# this for NFC flag
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
ADD_EXECUTABLE(${NDEF_TOOL} ${TOOL_SRC})
-TARGET_LINK_LIBRARIES(${NDEF_TOOL} ${tool_pkgs_LDFLAGS} "-lpthread -lrt -pie -ldl" "-L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/clientlib -L${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_tmp/src/commonlib" "-lnfc" "-lnfc-common-lib")
-
+TARGET_LINK_LIBRARIES(${NDEF_TOOL} ${tool_pkgs_LDFLAGS} pthread dl rt nfc-common-lib nfc)
+LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib ${CMAKE_BUILD_DIR}/src/clientlib)
INSTALL(TARGETS ${NDEF_TOOL} DESTINATION bin)
}
__attribute__((packed)) net_nfc_certificate_chain_s;
+void _display_ndef_message(ndef_message_h msg);
+
static void _display_buffer(char *title, uint8_t *buffer, uint32_t length)
{
int32_t i;
}
}
+static void _display_hs(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+
+ fprintf(stdout, " Version : %d.%d\n", ((*buffer) >> 4) & 0x0F,
+ (*buffer) & 0x0F);
+ fprintf(stdout, " -- Containing NDEF message -- \n");
+
+ ndef_message_h msg;
+ data_h temp;
+
+ net_nfc_create_data(&temp, buffer + 1, length - 1);
+ net_nfc_create_ndef_message_from_rawdata(&msg, temp);
+
+ _display_ndef_message(msg);
+
+ net_nfc_free_ndef_message(msg);
+ net_nfc_free_data(temp);
+ }
+}
+
+static void _display_hr(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ uint32_t length = net_nfc_get_data_length(data);
+
+ fprintf(stdout, " Version : %d.%d\n", ((*buffer) >> 4) & 0x0F,
+ (*buffer) & 0x0F);
+ fprintf(stdout, " -- Containing NDEF message -- \n");
+
+ ndef_message_h msg;
+ data_h temp;
+
+ net_nfc_create_data(&temp, buffer + 1, length - 1);
+ net_nfc_create_ndef_message_from_rawdata(&msg, temp);
+
+ _display_ndef_message(msg);
+
+ net_nfc_free_ndef_message(msg);
+ net_nfc_free_data(temp);
+ }
+}
+
+static void _display_ac(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ int i, len;
+ const char *flag = "unknown";
+
+ switch (*buffer)
+ {
+ case 0 :
+ flag = "inactive";
+ break;
+
+ case 1 :
+ flag = "active";
+ break;
+
+ case 2 :
+ flag = "activating";
+ break;
+
+ default :
+ break;
+ }
+
+ fprintf(stdout, " Carrier Flags : 0x%x (%s)\n", *buffer++, flag);
+ len = *buffer++;
+ fprintf(stdout, " Carrier Data Ref. len : %d byte(s)\n", len);
+
+ for (i = 0; i < len; i++)
+ {
+ fprintf(stdout, " Carrier Data Ref. [%d] : %c\n", i, *buffer++);
+ }
+
+ len = *buffer++;
+ fprintf(stdout, " Aux. Data Ref. len : %d byte(s)\n", len);
+
+ for (i = 0; i < len; i++)
+ {
+ fprintf(stdout, " Aux. Data Ref. [%d] : %c\n", i, *buffer++);
+ }
+ }
+}
+
+static void _display_hc(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ int i, len;
+ const char *flag = "unknown";
+ uint8_t ctf = (*buffer) & 0x07;
+
+ switch (ctf)
+ {
+ case 1 :
+ flag = "Well-known type";
+ break;
+
+ case 2 :
+ flag = "MIME type";
+ break;
+
+ case 3 :
+ flag = "Absolute URI";
+ break;
+
+ case 4 :
+ flag = "External";
+ break;
+
+ default :
+ break;
+ }
+
+ fprintf(stdout, " Carrier type format : 0x%02x (%s)\n", ctf, flag);
+ buffer++;
+
+ len = *buffer++;
+ fprintf(stdout, " Carrier type length : %d byte(s)\n", len);
+
+ for (i = 0; i < len; i++)
+ {
+ fprintf(stdout, " Carrier type [%d] : 0x%02x\n", i, *buffer++);
+ }
+
+ len = net_nfc_get_data_length(data) - len - 2;
+
+ for (i = 0; i < len; i++)
+ {
+ fprintf(stdout, " Carrier data [%d] : 0x%02x\n", i, *buffer++);
+ }
+ }
+}
+
+static void _display_cr(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+
+ fprintf(stdout, " Random number : %02X %02X\n", buffer[0], buffer[1]);
+ }
+}
+
+static void _display_err(ndef_record_h record)
+{
+ data_h data = NULL;
+
+ _display_id(record);
+
+ net_nfc_get_record_payload(record, &data);
+ if (net_nfc_get_data_length(data) > 0)
+ {
+ uint8_t *buffer = net_nfc_get_data_buffer(data);
+ const char *reason = "unknown";
+
+ switch (buffer[0])
+ {
+ case 1 :
+ reason = "temporary memory constraint";
+ break;
+
+ case 2 :
+ reason = "permanent memory constraint";
+ break;
+
+ case 3 :
+ reason = "carrier-specific constraint";
+ break;
+
+ default :
+ break;
+ }
+
+ fprintf(stdout, " Error reason : %s\n", reason);
+ fprintf(stdout, " Error data : %d ms\n", buffer[1]);
+ }
+}
+
static void _display_well_known(ndef_record_h record)
{
data_h data = NULL;
}
else if (strncmp(temp_buffer, "Gc", 2) == 0)
{
- fprintf(stdout, " Type string[%d] : %s (General control)\n", length, temp_buffer);
+ fprintf(stdout, " Type string[%d] : %s (Generic control)\n", length, temp_buffer);
}
else if (strncmp(temp_buffer, "U", 1) == 0)
{
fprintf(stdout, " Type string[%d] : %s (Text)\n", length, temp_buffer);
_display_text(record);
}
+ else if (strncmp(temp_buffer, "Hc", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Handover carrier)\n", length, temp_buffer);
+ _display_hc(record);
+ }
+ else if (strncmp(temp_buffer, "Hr", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Handover request)\n", length, temp_buffer);
+ _display_hr(record);
+ }
+ else if (strncmp(temp_buffer, "Hs", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Handover select)\n", length, temp_buffer);
+ _display_hs(record);
+ }
+ else if (strncmp(temp_buffer, "ac", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (alternative carrier)\n", length, temp_buffer);
+ _display_ac(record);
+ }
+ else if (strncmp(temp_buffer, "cr", 2) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Collision Resolution)\n", length, temp_buffer);
+ _display_cr(record);
+ }
+ else if (strncmp(temp_buffer, "err", 3) == 0)
+ {
+ fprintf(stdout, " Type string[%d] : %s (Error record)\n", length, temp_buffer);
+ _display_err(record);
+ }
else
{
fprintf(stdout, " Type string[%d] : %s (Unknown)\n", length, temp_buffer);
static void _display_record_length(ndef_record_h record)
{
- int length = 1;
+ int length = 2; /* header : 1 byte, type length : 1 byte */
net_nfc_record_tnf_e tnf = NET_NFC_RECORD_UNKNOWN;
{
uint8_t header;
- fprintf(stdout, "------------------ ndef record %02d ------------------\n", index);
+ fprintf(stdout, "------------------ NDEF record %02d ------------------\n", index);
_display_record_length(record);
fprintf(stdout, "----------------------------------------------------\n");
}
+void _display_ndef_message(ndef_message_h msg)
+{
+ uint32_t length;
+ int count = 0;
+ int32_t i = 0;
+ ndef_record_h record = NULL;
+
+ net_nfc_get_ndef_message_byte_length(msg, &length);
+
+ fprintf(stdout, "================ NDEF message begin ================\n");
+ fprintf(stdout, "Length : %d\n", length);
+
+ net_nfc_get_ndef_message_record_count(msg, &count);
+
+ for (i = 0; i < count; i++)
+ {
+ net_nfc_get_record_by_index(msg, i, &record);
+
+ _display_record(record, i);
+ }
+
+ fprintf(stdout, "================= NDEF message end =================\n");
+}
+
+
void ndef_tool_display_ndef_message_from_file(const char *file_name)
{
int length = 0;
if ((length = ndef_tool_read_ndef_message_from_file(file_name, &msg)) > 0)
{
- int32_t count = 0;
- int32_t i = 0;
- ndef_record_h record = NULL;
+ fprintf(stdout, "\n");
- net_nfc_get_ndef_message_record_count(msg, &count);
-
- fprintf(stdout, "\n================ ndef message begin ================\n");
- fprintf(stdout, "Length : %d\n", length);
-
- for (i = 0; i < count; i++)
- {
- net_nfc_get_record_by_index(msg, i, &record);
-
- _display_record(record, i);
- }
+ _display_ndef_message(msg);
- fprintf(stdout, "================= ndef message end =================\n\n");
+ fprintf(stdout, "\n");
net_nfc_free_ndef_message(msg);
}
net_nfc_free_exchanger_data(data_handle);
}
-void _nfc_response_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data)
+static void _handover_completed_cb(net_nfc_error_e result,
+ data_h data, void *user_data)
+{
+// response_context_t *context = (response_context_t *)user_data;
+// data_h rawdata;
+
+ if (result == NET_NFC_OK)
+ fprintf(stdout, "handover success!!!\n\n");
+ else
+ fprintf(stdout, "handover failed.\n\n");
+
+// net_nfc_create_rawdata_from_ndef_message((ndef_message_h)context->user_param, &rawdata);
+//
+// net_nfc_ex
+ g_main_loop_quit(main_loop);
+}
+
+static void _open_se_cb(net_nfc_error_e result, net_nfc_target_handle_h handle,
+ void *user_data)
+{
+ response_context_t *context = (response_context_t *)user_data;
+
+ if (result == NET_NFC_OK)
+ {
+ data_h data = NULL;
+
+ fprintf(stdout, "net_nfc_open_internal_secure_element success!!!\n\n");
+
+ net_nfc_create_data(&data, (uint8_t *)context->user_param,
+ context->type);
+ if (data != NULL) {
+ net_nfc_send_apdu(handle, data, handle);
+ net_nfc_free_data(data);
+ }
+ }
+ else
+ {
+ fprintf(stdout, "net_nfc_open_internal_secure_element failed.\n\n");
+ g_main_loop_quit(main_loop);
+ }
+}
+
+static void _send_apdu_se_cb(net_nfc_error_e result, net_nfc_target_handle_h handle, void *user_data)
+{
+// response_context_t *context = (response_context_t *)user_data;
+// data_h rawdata;
+
+ if (result == NET_NFC_OK)
+ {
+ fprintf(stdout, "net_nfc_send_apdu success!!!\n\n");
+ net_nfc_close_internal_secure_element(handle, user_data);
+ }
+ else
+ {
+ fprintf(stdout, "net_nfc_send_apdu failed.\n\n");
+ g_main_loop_quit(main_loop);
+ }
+}
+
+static void _close_se_cb(net_nfc_error_e result, void *user_data)
+{
+ if (result == NET_NFC_OK)
+ fprintf(stdout, "net_nfc_close_internal_secure_element success!!!\n\n");
+ else
+ fprintf(stdout, "net_nfc_close_internal_secure_element failed.\n\n");
+
+ g_main_loop_quit(main_loop);
+}
+
+static void _handover_cb(net_nfc_target_handle_h handle, void *user_data)
+{
+ fprintf(stdout, "\ntry to handover...\n\n");
+
+ net_nfc_exchanger_request_connection_handover(handle,
+ NET_NFC_CONN_HANDOVER_CARRIER_BT);
+}
+
+void _nfc_response_cb(net_nfc_message_e message, net_nfc_error_e result,
+ void *data, void *user_param, void *trans_data)
{
response_context_t *context = (response_context_t *)user_param;
{
_p2p_send_cb((net_nfc_target_handle_h)data, user_param);
}
+ else if (context->type == 2) /* handover */
+ {
+ _handover_cb((net_nfc_target_handle_h)data, user_param);
+ }
break;
case NET_NFC_MESSAGE_P2P_SEND :
_p2p_receive_completed_cb(data, user_param);
break;
+ case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
+ _handover_completed_cb(result, data, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
+ _open_se_cb(result, data, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_SEND_APDU_SE :
+ _send_apdu_se_cb(result, trans_data, user_param);
+ break;
+
+ case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
+ _close_se_cb(result, user_param);
+ break;
+
default :
break;
}
static void _initialize_tag_context(response_context_t *context)
{
- if(!g_thread_supported())
+ int ret = 0;
+
+ if (!g_thread_supported())
{
g_thread_init(NULL);
}
-// g_type_init();
-
- net_nfc_initialize();
-
- net_nfc_set_response_callback(_nfc_response_cb, (void *)context);
+ ret = net_nfc_initialize();
+ if (ret == NET_NFC_OK)
+ {
+ net_nfc_set_response_callback(_nfc_response_cb, (void *)context);
+ }
}
static void _run_tag_action()
_initialize_tag_context(&response_context);
- fprintf(stdout, "Contact a tag to device.....\n");
+ fprintf(stdout, "Contact a target to device.....\n");
+
+ _run_tag_action();
+
+ net_nfc_free_ndef_message(msg);
+
+ _release_tag_context();
+ }
+
+ return result;
+}
+
+static int _make_file_to_ndef_message(ndef_message_h *msg, const char *file_name)
+{
+ int result = 0;
+ FILE *file = NULL;
+
+ file = fopen(file_name, "rb");
+ if (file != NULL)
+ {
+ long int file_size = 0;
+ size_t read = 0;
+
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ if (file_size > 0)
+ {
+ data_h data;
+
+ net_nfc_create_data(&data, NULL, file_size);
+ if (data != NULL)
+ {
+ ndef_record_h record;
+ data_h type;
+
+ read = fread((void *)net_nfc_get_data_buffer(data), 1, file_size, file);
+
+ net_nfc_create_ndef_message(msg);
+
+ net_nfc_create_data(&type, (uint8_t *)"image/jpeg", 10);
+
+ net_nfc_create_record(&record, NET_NFC_RECORD_MIME_TYPE, type, NULL, data);
+
+ net_nfc_append_record_to_ndef_message(*msg, record);
+
+ net_nfc_free_data(type);
+ net_nfc_free_data(data);
+
+ result = file_size;
+ }
+ }
+
+ fclose(file);
+ }
+
+ return result;
+}
+
+int ndef_tool_connection_handover(const char *file)
+{
+ int result = 0;
+ ndef_message_h msg = NULL;
+
+ if (_make_file_to_ndef_message(&msg, file) > 0)
+ {
+ response_context.type = 2;
+ response_context.user_param = (void *)msg;
+
+ _initialize_tag_context(&response_context);
+
+ fprintf(stdout, "Contact a target to device.....\n");
_run_tag_action();
return result;
}
+static unsigned char char_to_num[] =
+{
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+};
+
+int _convert_string_to_hex(const char *str, unsigned char *buffer, size_t length)
+{
+ size_t i, j, len = strlen(str);
+
+ for (i = 0, j = 0; i < len; j++)
+ {
+ buffer[j] = (char_to_num[(unsigned char)str[i++]] << 4);
+ if (i < len)
+ {
+ buffer[j] |= char_to_num[(unsigned char)str[i++]];
+ }
+ }
+
+ return (int)j;
+}
+
+int ndef_tool_send_apdu(const char *apdu)
+{
+ int result = 0;
+ unsigned char *buffer;
+ unsigned int length = (strlen(apdu) >> 1) + 1;
+
+ buffer = calloc(1, length);
+ if (buffer != NULL)
+ {
+ length = _convert_string_to_hex(apdu, buffer, length);
+ if (length > 0)
+ {
+ response_context.type = length;
+ response_context.user_param = (void *)buffer;
+
+ _initialize_tag_context(&response_context);
+
+ fprintf(stdout, "try to open eSE.....\n");
+
+ net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, buffer);
+
+ _run_tag_action();
+
+
+ _release_tag_context();
+ }
+
+ free(buffer);
+ }
+
+ return result;
+}
static GMainLoop *main_loop = NULL;
-void _activation_complete_cb(net_nfc_message_e message, net_nfc_error_e result, void *data, void *user_param, void *trans_data)
+void _activation_complete_cb(net_nfc_message_e message, net_nfc_error_e result,
+ void *data, void *user_param, void *trans_data)
{
switch (message)
{
fprintf(stdout, " --write-tag Write a ndef file to tag\n");
fprintf(stdout, " --receive-ndef Receive a ndef from target device and store to file\n");
fprintf(stdout, " --send-ndef Send a ndef file to target device\n");
+ fprintf(stdout, " --handover Try to handover another carrier\n");
fprintf(stdout, "\n");
fprintf(stdout, " -h, --help Show this help messages\n");
fprintf(stdout, "\n");
{
operation = OPERATION_SEND_NDEF;
}
+ else if (__COMPARE_OPTION(argv[i], 0, "handover"))
+ {
+ operation = OPERATION_HANDOVER;
+ }
else if (__COMPARE_OPTION(argv[i], 0, "off")) /* hidden operation */
{
operation = OPERATION_OFF;
{
operation = OPERATION_ON;
}
+ else if (__COMPARE_OPTION(argv[i], 0, "send-apdu")) /* hidden operation */
+ {
+ operation = OPERATION_SEND_APDU;
+ }
+ else if (__COMPARE_OPTION(argv[i], 0, "set-se")) /* hidden operation */
+ {
+ operation = OPERATION_SET_SE;
+ }
else if (__COMPARE_OPTION(argv[i], 'i', "record-index"))
{
__DO_NEXT_ARG;
ndef_tool_send_ndef_via_p2p(file_name);
break;
+ case OPERATION_HANDOVER :
+ ndef_tool_connection_handover(file_name);
+ break;
+
case OPERATION_ON :
{
int state = 0;
}
break;
+ case OPERATION_SEND_APDU :
+ ndef_tool_send_apdu(file_name);
+ break;
+
+ case OPERATION_SET_SE :
+ net_nfc_initialize();
+
+ if (strcmp(file_name, "SIM1") == 0) {
+ net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
+ } else if (strcmp(file_name, "eSE") == 0) {
+ net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_ESE, NULL);
+ } else {
+ fprintf(stdout, "Unknown SE name.\n\n");
+ }
+ break;
+
case OPERATION_ERROR :
default :
print_usage(argv[0]);
return 0;
}
-
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
-#ifndef __NDEF_TOOL_H
-#define __NDEF_TOOL_H
+#ifndef __NDEF_TOOL_H__
+#define __NDEF_TOOL_H__
#include "net_nfc_typedef.h"
OPERATION_WRITE_TAG,
OPERATION_RECEIVE_NDEF,
OPERATION_SEND_NDEF,
+ OPERATION_HANDOVER,
+ OPERATION_SEND_APDU,
OPERATION_ON, /* hidden operation */
OPERATION_OFF, /* hidden operation */
+ OPERATION_SET_SE, /* hidden operation */
};
int ndef_tool_read_ndef_message_from_file(const char *file_name, ndef_message_h *msg);
int ndef_tool_write_ndef_to_tag(const char *file);
int ndef_tool_receive_ndef_via_p2p(const char *file);
int ndef_tool_send_ndef_via_p2p(const char *file);
+int ndef_tool_connection_handover(const char *file);
+int ndef_tool_send_apdu(const char *apdu);
-
-
-#endif /* __NDEF_TOOL_H */
-
+#endif //__NDEF_TOOL_H__
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(nfc_client C)
+
+SET(NFC_CLIENT "nfc_client")
+
+include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
+include_directories(${CMAKE_SOURCE_DIR}/src/clientlib/include)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ TOOL_SRC)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Release")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(tool_pkgs REQUIRED glib-2.0 gobject-2.0)
+
+FOREACH(flag ${tool_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+# this for NFC flag
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -Werror-implicit-function-declaration -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
+
+SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpie")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" MATCHES "^arm.*")
+ ADD_DEFINITIONS("-DTARGET")
+ MESSAGE("add -DTARGET")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
+ENDIF()
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+ADD_EXECUTABLE(${NFC_CLIENT} ${TOOL_SRC})
+
+TARGET_LINK_LIBRARIES(${NFC_CLIENT} ${tool_pkgs_LDFLAGS} pthread dl rt nfc-common-lib nfc)
+LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/commonlib ${CMAKE_BUILD_DIR}/src/clientlib)
+
+INSTALL(TARGETS ${NFC_CLIENT} DESTINATION bin)
+
+
#include <stdio.h>
#include <stdlib.h>
-#include <net_nfc_typedef.h>
#include <net_nfc.h>
-#include <net_nfc_exchanger.h>
-
+#include <unistd.h>
#include <pthread.h>
#include "nfc_api_test.h"
{NULL, NULL, NET_NFC_TEST_NOT_YET},
};
-static uint32_t testDevType = 0;
-static uint32_t testCardMaxNdefLength = 0;
-static uint8_t tagTestResult[NET_NFC_MAX_TAG_TYPE];
+//static uint32_t testDevType = 0;
+//static uint32_t testCardMaxNdefLength = 0;
+//static uint8_t tagTestResult[NET_NFC_MAX_TAG_TYPE];
static int read_count = 0;
static int write_count = 0;
static gboolean test_process_func(gpointer data)
{
- uint8_t i, testNumber;
+ uint8_t i;
int count = 0;
while (nfcTestMatrix[count].testName != NULL){
net_nfc_create_data(&payload, buffer, 1024);
*/
- if((error = net_nfc_create_exchanger_data(&ex_data, (uint8_t *)"http://www.samsung.com")) == NET_NFC_OK)
+ if((error = net_nfc_create_exchanger_data(&ex_data, payload/*(uint8_t *)"http://www.samsung.com"*/)) == NET_NFC_OK)
//if((error = net_nfc_create_exchanger_url_type_data(&ex_data, NET_NFC_SCHEMA_FULL_URI, (uint8_t *)"file://test.txt")) == NET_NFC_OK)
//if((error = net_nfc_create_exchanger_raw_type_data(&ex_data, "text/plain", payload)) == NET_NFC_OK)
{
/*=================================================================================*/
static void net_nfc_test_reader_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
{
- int user_context;
+ //int user_context;
- PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
+ PRINT_INFO("user_param = [%p] trans_param = [%p]", user_param, trans_data);
switch(message)
{
net_nfc_get_tag_handle(target_info, &id);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %X\n", id);
+ PRINT_INFO("target id: %p\n", id);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
if (is_ndef){
- int actual_size;
- int max_size;
- net_nfc_get_tag_actual_data_size (target_info ,&actual_size);
+ uint32_t actual_size;
+ uint32_t max_size;
+ net_nfc_get_tag_actual_data_size (target_info, &actual_size);
net_nfc_get_tag_max_data_size (target_info ,&max_size);
PRINT_INFO("\tmax data [%d]\tactual data [%d]\n", max_size,actual_size );
net_nfc_read_tag (id, (void *)2);
data_h rawdata;
net_nfc_create_rawdata_from_ndef_message (ndef ,&rawdata);
PRINT_INFO("read ndef message is ok, length is [%d]", net_nfc_get_data_length(rawdata));
+ net_nfc_free_data(rawdata);
//_//net_nfc_ndef_print_message (ndef);
/*
static void net_nfc_test_format_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
{
- int user_context;
+ //int user_context;
- PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
+ PRINT_INFO("user_param = [%p] trans_param = [%p]", user_param, trans_data);
switch(message)
{
net_nfc_get_tag_handle(target_info, &id);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %X\n", id);
+ PRINT_INFO("target id: %p\n", id);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
data_h ndef_key = NULL;
net_nfc_mifare_create_net_nfc_forum_key(&ndef_key);
net_nfc_format_ndef(id, ndef_key, NULL);
+ net_nfc_free_data(ndef_key);
}
break;
break;
case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
{
- PRINT_INFO("NET_NFC_MESSAGE_OPEN_INTERNAL_SE result = [%d] and handle = [0x%x]", result, data);
+ PRINT_INFO("NET_NFC_MESSAGE_OPEN_INTERNAL_SE result = [%p] and handle = [%p]", result, data);
data_h apdu = NULL;
uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C} ; // CLA 0-> use default channel and no secure message. 0xA4 -> select instruction
net_nfc_create_data(&apdu, apdu_cmd, 4);
net_nfc_send_apdu((net_nfc_target_handle_h)(data), apdu, data);
+ net_nfc_free_data(apdu);
}
break;
break;
}
- PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
+ PRINT_INFO("user_param = [%p] trans_param = [%p]", user_param, trans_data);
}
/*=================================================================================*/
static void net_nfc_test_static_handover_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
{
- int user_context;
+ //int user_context;
switch(message)
{
case NET_NFC_MESSAGE_TAG_DISCOVERED:{
net_nfc_target_handle_h id;
bool is_ndef;
net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_carrier_config_h * config;
+ net_nfc_carrier_config_h config;
ndef_record_h record;
net_nfc_get_tag_type (target_info, &type);
net_nfc_get_tag_handle(target_info, &id);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %X\n", id);
+ PRINT_INFO("target id: %p\n", id);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
if (is_ndef){
net_nfc_add_carrier_config_property (config ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,8 ,temp);
net_nfc_create_ndef_record_with_carrier_config (&record, config);
net_nfc_create_handover_select_message (&ndef);
- net_nfc_append_carrier_config_record (message,record,NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
-
+ net_nfc_append_carrier_config_record (ndef,record,NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
net_nfc_write_ndef(id, ndef, NULL);
+ net_nfc_free_record(record);
+ net_nfc_free_data(bt_config);
+ net_nfc_free_carrier_config(config);
}
else{
int nfcConnHandover(uint8_t testNumber,void* arg_ptr2)
{
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
#if 1
test_case_result = NET_NFC_TEST_FAIL;
result = net_nfc_initialize();
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
CHECK_RESULT(result);
result = net_nfc_set_response_callback (net_nfc_test_static_handover_cb, NULL);
{
PRINT_INFO("%s is start", __func__);
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
result = net_nfc_initialize();
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
CHECK_RESULT(result);
result = net_nfc_set_response_callback (net_nfc_test_format_cb, (void *)1);
result = net_nfc_initialize();
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
CHECK_RESULT(result);
result = net_nfc_set_response_callback (net_nfc_test_se_cb, (void *)1);
{
PRINT_INFO("%s is start", __func__);
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
result = net_nfc_initialize();
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
CHECK_RESULT(result);
result = net_nfc_set_response_callback (net_nfc_test_reader_cb, (void *)1);
net_nfc_get_tag_handle (target_info, &handle);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %X\n", handle);
+ PRINT_INFO("target id: %p\n", handle);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
tag_handle = handle;
int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2)
{
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
result = net_nfc_set_response_callback (net_nfc_test_write_cb, NULL);
CHECK_RESULT(result);
int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2)
{
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
result = net_nfc_set_response_callback (net_nfc_test_read_write_cb, NULL);
CHECK_RESULT(result);
static void net_nfc_test_transceive_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
{
- int user_context;
+ //int user_context;
printf ("callback is called with message %d\n", message);
switch(message)
net_nfc_get_tag_handle (target_info, &id);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %X\n", id);
+ PRINT_INFO("target id: %p\n", id);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
tag_handle = id;
int nBlocks = 0;
- if(type == NET_NFC_MIFARE_4K_PICC && sector > 31){
+// if(type == NET_NFC_MIFARE_4K_PICC && sector > 31){
+//
+// nBlocks = 16;
+// }
+// else{
+// nBlocks = 4;
+// }
- nBlocks = 16;
- }
- else{
- nBlocks = 4;
- }
+ nBlocks = 4;
/*
}
*/
- net_nfc_free_data(mad_key);
- net_nfc_free_data(default_key);
- net_nfc_free_data(net_nfc_forum_key);
}
-
+ net_nfc_free_data(key);
+ net_nfc_free_data(default_key);
+ net_nfc_free_data(mad_key);
+ net_nfc_free_data(net_nfc_forum_key);
}
else if(type == NET_NFC_JEWEL_PICC){
else if(test_count == 5){
PRINT_INFO("auth key A is success = [%d]", result);
test_case_result = NET_NFC_TEST_OK;
- net_nfc_error_e result = NET_NFC_OK;
+ //net_nfc_error_e result = NET_NFC_OK;
/*
if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
#define NUM_OF_THREAD 10
#define REQUEST_PER_THREAD 5
-static number_of_read_completed = 0;
+static int number_of_read_completed = 0;
static void* net_nfc_read_ndef_test(void* handle)
{
}
static void net_nfc_test_multiple_request_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
{
- int user_context;
+ //int user_context;
printf ("callback is called with message %d\n", message);
net_nfc_get_tag_handle (target_info, &handle);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target handle: %X\n", handle);
+ PRINT_INFO("target handle: %p\n", handle);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
test_case_result = NET_NFC_TEST_OK;
PRINT_INFO("read ndef msg");
number_of_read_completed ++;
- ndef_message_h ndef = (ndef_message_h)(data);
+ //ndef_message_h ndef = (ndef_message_h)(data);
////net_nfc_ndef_print_message(ndef);
static void net_nfc_test_detected_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
{
- int user_context;
+ //int user_context;
printf ("callback is called with message %d\n", message);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target handle: %X\n", id);
+ PRINT_INFO("target handle: %p\n", id);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
char** keys = NULL;
uint32_t data_length = net_nfc_get_data_length(value);
uint8_t* data_buffer = net_nfc_get_data_buffer(value);
- PRINT_INFO("\n key >> ", keys[i]);
+ PRINT_INFO("\n key [%s] >> ", keys[i]);
if(data_length > 1)
{
for(; index < data_length; index++)
static void net_nfc_test_read_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
{
- int user_context;
+ //int user_context;
switch(message)
{
net_nfc_get_tag_handle (target_info, &handle);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target handle: %X\n", handle);
+ PRINT_INFO("target handle: %p\n", handle);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
if(is_ndef)
{
if(data != NULL){
- ndef_message_h ndef = (ndef_message_h)(data);
+ //ndef_message_h ndef = (ndef_message_h)(data);
////net_nfc_ndef_print_message(ndef);
net_nfc_get_tag_handle (target_info, &handle);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target handle: %X\n", handle);
+ PRINT_INFO("target handle: %p\n", handle);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
if(is_ndef)
}
if(data != NULL){
- ndef_message_h ndef = (ndef_message_h)(data);
+ //ndef_message_h ndef = (ndef_message_h)(data);
////net_nfc_ndef_print_message(ndef);
int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2)
{
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
result = net_nfc_set_response_callback (net_nfc_test_multiple_request_cb, NULL);
CHECK_RESULT(result);
int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2)
{
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
- int length = 0;
+ //int length = 0;
/*
char** keys = NULL;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
result = net_nfc_set_response_callback (net_nfc_test_detected_cb, NULL);
int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2)
{
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
read_count = 0;
int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2)
{
- int user_context = 0;
- net_nfc_error_e result;
+ //int user_context = 0;
+ //net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
ndef_message_h ndef_message = NULL;
if(net_nfc_get_record_type(record, &type) == NET_NFC_OK && net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
{
- if(strcmp(net_nfc_get_data_buffer(type), "Sp") == 0)
+ if(strcmp((char*)net_nfc_get_data_buffer(type), "Sp") == 0)
{
}
- else if(strcmp(net_nfc_get_data_buffer(type), "T") == 0)
+ else if(strcmp((char*)net_nfc_get_data_buffer(type), "T") == 0)
{
net_nfc_encode_type_e utf;
- uint32_t utf_length = 0;
- uint32_t lang_length = 0;
+ //uint32_t utf_length = 0;
+ //uint32_t lang_length = 0;
char* text = NULL;
- uint32_t text_length = 0;
+ //uint32_t text_length = 0;
char* language_code_str = NULL;
if(net_nfc_get_encoding_type_from_text_record(record, &utf) == NET_NFC_OK)
{
- PRINT_INFO("utf = [%s]", utf);
+ PRINT_INFO("utf = [%d]", utf);
}
else
{
if(text != NULL)
free(text);
+ if(language_code_str != NULL)
+ free(language_code_str);
/*
uint8_t* utf = NULL;
uint8_t* language_code = NULL;
test_case_result = NET_NFC_TEST_OK;
*/
}
- else if(strcmp(net_nfc_get_data_buffer(type), "U") == 0)
+ else if(strcmp((char*)net_nfc_get_data_buffer(type), "U") == 0)
{
}
}
}
-
- CHECK_RESULT(result);
+ net_nfc_free_ndef_message(ndef_message);
+ //CHECK_RESULT(result);
return test_case_result;
}
int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2)
{
- int user_context = 0;
+ //int user_context = 0;
net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate(1);
+ net_nfc_state_activate();
result = net_nfc_set_response_callback (net_nfc_test_transceive_cb, NULL);
CHECK_RESULT(result);
//_//net_nfc_ndef_print_message (uriMsg);
- result = net_nfc_create_data (&type_data ,"U", 1);
+ result = net_nfc_create_data (&type_data ,(uint8_t*)"U", 1);
CHECK_RESULT(result);
result = net_nfc_search_record_by_type (uriMsg ,NET_NFC_RECORD_WELL_KNOWN_TYPE ,type_data ,&record);
result = net_nfc_create_rawdata_from_ndef_message (uriMsg, &raw_data);
CHECK_RESULT(result);
- result = net_nfc_create_data (&type_data, smart_poster_type, strlen (smart_poster_type));
+ result = net_nfc_create_data (&type_data, (uint8_t*)smart_poster_type, strlen (smart_poster_type));
+ if (result != NET_NFC_OK) {
+ net_nfc_free_data(raw_data);
+ net_nfc_free_data(type_data);
+ net_nfc_free_ndef_message(uriMsg);
+ }
CHECK_RESULT(result);
result = net_nfc_create_record (&spRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE,type_data , NULL, raw_data);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_data(raw_data);
+ net_nfc_free_data(type_data);
+ net_nfc_free_ndef_message(uriMsg);
+ }
CHECK_RESULT(result);
result = net_nfc_create_ndef_message (&spMsg);
net_nfc_free_data (type_data);
net_nfc_free_data (raw_data);
+ net_nfc_free_ndef_message(uriMsg);
return test_case_result;
}
static void net_nfc_client_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
{
PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
- int x;
+ //int x;
switch (message)
{
case NET_NFC_MESSAGE_LLCP_LISTEN:
PRINT_INFO ("LLCP connect is completed with error code %d", result);
data_h data;
char * str = "Client message: Hello, server!";
- net_nfc_create_data (&data, str ,strlen (str) + 1);
+ net_nfc_create_data (&data, (uint8_t*)str ,strlen (str) + 1);
net_nfc_send_llcp (client_socket, data, NULL);
+ net_nfc_free_data(data);
}
break;
case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
data_h data;
char * str = "Server message: Welcome NFC llcp world!";
- net_nfc_create_data (&data, str ,strlen (str) + 1);
+ net_nfc_create_data (&data, (uint8_t*)str ,strlen (str) + 1);
net_nfc_send_llcp (accepted_socket, data, NULL);
+ net_nfc_free_data(data);
}
break;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
result = net_nfc_set_response_callback (net_nfc_test_snep_cb, NULL);
PRINT_INSTRUCT("START SNEP test !!");
net_nfc_llcp_config_info_h config;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
result = net_nfc_set_response_callback (net_nfc_test_llcp_cb, NULL);
CHECK_RESULT(result);
result = net_nfc_create_llcp_configure_default (&config);
result = net_nfc_deinitialize ();
CHECK_RESULT(result);
*/
-
+ net_nfc_free_llcp_configure(config);
return NET_NFC_TEST_OK;
}
static void net_nfc_client_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
{
PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
- int x;
+ //int x;
switch (message)
{
case NET_NFC_MESSAGE_LLCP_LISTEN:
PRINT_INFO ("LLCP connect is completed with error code %d", result);
data_h data;
char * str = "Client message: Hello, server!";
- net_nfc_create_data (&data, str ,strlen (str) + 1);
+ net_nfc_create_data (&data, (uint8_t*)str ,strlen (str) + 1);
net_nfc_send_llcp (client_socket, data, NULL);
+ net_nfc_free_data(data);
}
break;
case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
data_h data;
char * str = "Server message: Welcome NFC llcp world!";
- net_nfc_create_data (&data, str ,strlen (str) + 1);
+ net_nfc_create_data (&data, (uint8_t*)str ,strlen (str) + 1);
net_nfc_send_llcp (server_socket, data, NULL);
+ net_nfc_free_data(data);
}
break;
net_nfc_llcp_config_info_h config;
result = net_nfc_initialize();
CHECK_RESULT(result);
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
result = net_nfc_set_response_callback (net_nfc_test_llcp_stress_cb, NULL);
CHECK_RESULT(result);
result = net_nfc_create_llcp_configure_default (&config);
result = net_nfc_deinitialize ();
CHECK_RESULT(result);
*/
-
+ net_nfc_free_llcp_configure(config);
return NET_NFC_TEST_OK;
}
int nfcTestAPIException (uint8_t testNumber,void* arg_ptr)
{
- net_nfc_error_e result;
+ //net_nfc_error_e result;
test_case_result = NET_NFC_TEST_FAIL;
CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb1, NULL));
CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
PRINT_INSTRUCT("Please close a tag to device!!");
sleep (2);
CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
- net_nfc_state_activate (1);
- net_nfc_state_activate (1);
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
+ net_nfc_state_activate ();
+ net_nfc_state_activate ();
PRINT_INSTRUCT("Please close a tag to device!!");
PRINT_INSTRUCT("Please remove the tag from device!!");
sleep (2);
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
PRINT_INSTRUCT("Please close a tag to device!!");
net_nfc_target_handle_h id;
bool is_ndef;
net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
- net_nfc_error_e e_ret ;
+ //net_nfc_error_e e_ret ;
net_nfc_get_tag_type (target_info, &type);
net_nfc_get_tag_handle (target_info, &id);
net_nfc_get_tag_ndef_support (target_info, &is_ndef);
PRINT_INFO("target type: %d\n", type);
- PRINT_INFO("target id: %X\n", id);
+ PRINT_INFO("target id: %p\n", id);
PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
net_nfc_deinitialize (); // Before calling transceive
if (NET_NFC_OK == net_nfc_write_ndef (id ,message ,NULL)){
test_case_result = NET_NFC_TEST_FAIL;
}
+ net_nfc_free_ndef_message(message);
}
break;
net_nfc_target_handle_h id;
data_h key;
char data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
- net_nfc_create_data (&key, data, 6);
+ net_nfc_create_data (&key, (uint8_t*)data, 6);
net_nfc_get_tag_handle (target_info, &id);
net_nfc_deinitialize();
if (NET_NFC_OK == net_nfc_format_ndef(id, key, NULL)){
test_case_result = NET_NFC_TEST_FAIL;
}
+ net_nfc_free_data(key);
}
break;
+ default:
+ break;
}
pthread_mutex_lock (&plock);
pthread_mutex_unlock (&plock);
}
break;
+ default:
+ break;
}
}
/* Call API before initailize */
data_h key;
- char data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
+ net_nfc_error_e result;
+ uint8_t data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
net_nfc_create_data (&key, data, 6);
- CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_format_ndef(NULL, key, NULL));
+ result = net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL);
+ if(NET_NFC_OK == result){
+ net_nfc_free_data(key);
+ }
+ CHECK_ASSULT (NET_NFC_OK != result);
+ result = net_nfc_format_ndef(NULL, key, NULL);
+ if((NET_NFC_NULL_PARAMETER != result)||(NET_NFC_OK == net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL))||(NET_NFC_OK == net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL))||(NET_NFC_NULL_PARAMETER != net_nfc_read_tag (NULL ,NULL))){
+ net_nfc_free_data(key);
+ }
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == result);
CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL));
CHECK_ASSULT (NET_NFC_OK != net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL));
CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_read_tag (NULL ,NULL));
+ net_nfc_free_data(key);
ndef_message_h message = NULL;
ndef_record_h record = NULL;
net_nfc_create_ndef_message (&message);
net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
net_nfc_append_record_to_ndef_message (message ,record);
- CHECK_ASSULT (NET_NFC_OK != net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message,NULL));
- CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef (NULL ,message,NULL));
+ result = net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message,NULL);
+ if(NET_NFC_OK == result){
+ net_nfc_free_ndef_message (message);
+ }
+ CHECK_ASSULT (NET_NFC_OK != result);
+ result = net_nfc_write_ndef (NULL ,message,NULL);
+ if((NET_NFC_NULL_PARAMETER != result)||(NET_NFC_NULL_PARAMETER != net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL))){
+ net_nfc_free_ndef_message (message);
+ }
+ CHECK_ASSULT (NET_NFC_NULL_PARAMETER == result);
CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL));
net_nfc_free_ndef_message (message);
for (test_case = 0 ; test_case < 4; test_case++){
CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
PRINT_INSTRUCT("Please close a tag to device!!");
CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_tagAPI, &test_case));
pthread_cond_wait (&pcond,&plock );
break;
+ default:
+ break;
}
}
CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value(NULL, key, &value));
CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
- net_nfc_state_activate (1);
+ net_nfc_state_activate ();
CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_targetInfo, NULL));
PRINT_INSTRUCT("Please close a tag to device!!");
ndef_message_h message;
uint8_t buffer[256] = {0,};
uint8_t * pdata;
- int length = 0;
+ unsigned int length = 0;
net_nfc_error_e result;
char SSID[] = "HomeWLAN";
char dev_name[] = "DeviceName";
result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_INDEX, 1, buffer);
CHECK_RESULT(result);
- length = sprintf (buffer, "%s", SSID);
+ length = sprintf ((char*)buffer, "%s", SSID);
result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_SSID, length, buffer);
CHECK_RESULT(result);
result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE, 2, buffer);
CHECK_RESULT(result);
- length = sprintf (buffer, "MyPreSharedKey");
+ length = sprintf ((char*)buffer, "MyPreSharedKey");
result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_KEY, length, buffer);
CHECK_RESULT(result);
*((uint16_t*) buffer ) = 0x0001;
result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_CHANNEL, 2, buffer);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_carrier_group(group);
+ }
CHECK_RESULT(result);
buffer[0] = 0x00;
buffer[1] = 0x37;
buffer[2] = 0x2A;
result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_VEN_EXT, 3, buffer);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_carrier_group(group);
+ }
CHECK_RESULT(result);
result = net_nfc_append_carrier_config_group (carrier, group);
CHECK_RESULT(result);
result = net_nfc_create_handover_request_message (&message);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_record(carrier_record);
+ }
CHECK_RESULT(result);
//net_nfc_ndef_print_message (message);
buffer[3] = btdev_addr[3];
buffer[4] = btdev_addr[4];
buffer[5] = btdev_addr[5];
- result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,6 ,buffer);
+ if(carrier == NULL){
+ result = NET_NFC_NULL_PARAMETER;
+ }else{
+ result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,6 ,buffer);
+ }
CHECK_RESULT(result);
buffer[0] = 0x08;
result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_UUID16 ,4 ,buffer);
CHECK_RESULT(result);
- length = sprintf (buffer, "%s", dev_name);
+ length = sprintf ((char*)buffer, "%s", dev_name);
result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME ,length ,buffer);
CHECK_RESULT(result);
result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_carrier_config(carrier);
+ }
CHECK_RESULT(result);
result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING);
+ if (result != NET_NFC_OK) {
+ net_nfc_free_carrier_config(carrier);
+ }
CHECK_RESULT(result);
//net_nfc_ndef_print_message (message);
result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
CHECK_RESULT(result);
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_WIFI_ATTRIBUTE_VERSION , &length, &pdata);
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_WIFI_ATTRIBUTE_VERSION , (uint16_t*)&length, &pdata);
CHECK_RESULT(result);
if (pdata[0] != 0x10){
PRINT_RESULT_FAIL("FILE:%s, LINE:%d, value %d",__FILE__,__LINE__, pdata[0]);
result = net_nfc_get_carrier_config_group (carrier ,0 , &group);
CHECK_RESULT(result);
- result = net_nfc_get_carrier_config_group_property (group ,NET_NFC_WIFI_ATTRIBUTE_SSID, &length, &pdata);
+ result = net_nfc_get_carrier_config_group_property (group ,NET_NFC_WIFI_ATTRIBUTE_SSID, (uint16_t*)&length, &pdata);
CHECK_RESULT(result);
if (memcmp (pdata, SSID, length) != 0){
PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
CHECK_RESULT(result);
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , &length, &pdata);
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , (uint16_t*)&length, &pdata);
CHECK_RESULT(result);
if (memcmp (pdata, btdev_addr, length) != 0) {
PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
return NET_NFC_TEST_FAIL;
}
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , &length, &pdata);
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , (uint16_t*)&length, &pdata);
CHECK_RESULT(result);
if (memcmp (pdata, dev_name, length) != 0){
PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
CHECK_RESULT(result);
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , &length, &pdata);
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS, (uint16_t*)&length, &pdata);
CHECK_RESULT(result);
if (memcmp (pdata, btdev_addr, length) != 0) {
PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
return NET_NFC_TEST_FAIL;
}
- result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , &length, &pdata);
+ result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , (uint16_t*)&length, &pdata);
CHECK_RESULT(result);
if (memcmp (pdata, dev_name, length) != 0){
PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
-#ifndef __NET_NFC_TEST_H__
-#define __NET_NFC_TEST_H__
+#ifndef __NFC_API_TEST_H__
+#define __NFC_API_TEST_H__
typedef enum {
NET_NFC_TEST_NOT_YET,
uint8_t testResult;
} nfcTestType;
-
-
-
-#endif
-
+#endif //__NFC_API_TEST_H__
\ No newline at end of file
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+PROJECT(tests C)
+
+SET(NFC_CLIENT_TEST "nfc-client-test")
+
+include_directories(${CMAKE_SOURCE_DIR}/src/clientlib/include)
+include_directories(${CMAKE_SOURCE_DIR}/src/commonlib/include)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(tests_pkgs REQUIRED glib-2.0)
+
+FOREACH(flag ${tests_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fpie")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+ADD_EXECUTABLE(${NFC_CLIENT_TEST}
+ main.c
+ net_nfc_test_manager.c
+ net_nfc_test_tag.c
+ net_nfc_test_ndef.c
+ net_nfc_test_test.c
+ net_nfc_test_p2p.c
+ net_nfc_test_transceive.c
+ net_nfc_test_handover.c
+ net_nfc_test_client.c
+ net_nfc_test_jewel.c
+ net_nfc_test_tag_mifare.c
+ net_nfc_test_tag_felica.c
+ net_nfc_test_exchanger.c
+ net_nfc_test_llcp.c
+ net_nfc_test_snep.c
+ net_nfc_test_se.c
+ net_nfc_test_util.c
+ )
+
+TARGET_LINK_LIBRARIES(${NFC_CLIENT_TEST} ${tests_pkgs_LD_FLAGS} nfc)
+LINK_DIRECTORIES(${CMAKE_BUILD_DIR}/src/clientlib
+ ${CMAKE_BUILD_DIR}/src/commonlib)
--- /dev/null
+/*
+* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#ifndef __NET_NFC_TEST_CLIENT_H__
+#define __NET_NFC_TEST_CLIENT_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_initialize();
+
+void net_nfc_test_deinitialize();
+
+void net_nfc_test_is_nfc_supported();
+
+void net_nfc_test_get_nfc_state();
+
+#endif
+
--- /dev/null
+/*
+* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#ifndef __NET_NFC_TEST_EXCHANGER_H__
+#define __NET_NFC_TEST_EXCHANGER_H__
+
+
+#include <glib.h>
+#include "net_nfc_typedef.h"
+
+
+void net_nfc_test_create_exchanger_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_send_exchanger_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_exchanger_request_connection_handover(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_exchanger_get_alternative_carrier_type(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_exchanger_get_alternative_carrier_data(gpointer data,
+ gpointer user_data);
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_HANDOVER_H__
+#define __NET_NFC_TEST_HANDOVER_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_p2p_connection_handover(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_connection_handover_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_handover_get_alternative_carrier_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_handover_get_alternative_carrier_type(gpointer data,
+ gpointer user_data);
+
+
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_JEWEL_TAG_H__
+#define __NET_NFC_TEST_JEWEL_TAG_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_tag_jewel_read_id(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_jewel_read_byte(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_jewel_read_all(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_jewel_write_with_erase(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_jewel_write_with_no_erase(gpointer data,
+ gpointer user_data);
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_LLCP_H__
+#define __NET_NFC_TEST_LLCP_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_llcp_default_config(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_default_config_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_get_local_config(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_custom_config(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_custom_config_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_get_local_config(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_get_config_miu(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_get_config_wks(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_get_config_lto(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_get_config_option(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_set_config_miu(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_set_config_wks(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_set_config_lto(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_set_config_option(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_free_config(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_create_custom_socket_option(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_create_default_socket_option(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_get_local_socket_option(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_get_socket_option_miu(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_set_socket_option_miu(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_get_socket_option_rw(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_set_socket_option_rw(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_get_socket_option_type(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_set_socket_option_type(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_free_socket_option(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_listen(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_listen_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_receive(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_receive_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_receive_from(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_receive_from_sync(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_connect(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_connect_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_connect_sap(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_connect_sap_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_send(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_send_sync(gpointer data,
+ gpointer user_data);
+
+
+void net_nfc_test_llcp_send_to(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_send_to_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_disconnect(gpointer func_data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_disconnect_server(gpointer func_data,
+ gpointer user_data);
+
+void net_nfc_test_llcp_disconnect_sync(gpointer func_data,
+ gpointer user_data);
+
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_MANAGER_H__
+#define __NET_NFC_TEST_MANAGER_H__
+
+#include <glib.h>
+
+void net_nfc_test_manager_set_active(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_manager_get_server_state(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_manager_set_active_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_manager_get_server_state_sync(gpointer data,
+ gpointer user_data);
+
+#endif //__NET_NFC_TEST_MANAGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_NDEF_H__
+#define __NET_NFC_TEST_NDEF_H__
+
+#include <glib.h>
+
+void net_nfc_test_ndef_read(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_write(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_make_read_only(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_format(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_read_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_write_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_make_read_only_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_ndef_format_sync(gpointer data,
+ gpointer user_data);
+
+#endif //__NET_NFC_TEST_NDEF_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_P2P_H__
+#define __NET_NFC_TEST_P2P_H__
+
+
+#include <glib.h>
+#include "net_nfc_target_info.h"
+
+void net_nfc_test_p2p_send(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_send_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_set_device_discovered(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_set_device_detached(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_set_data_received(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_unset_device_discovered(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_unset_device_detached(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_p2p_unset_data_received(gpointer data,
+ gpointer user_data);
+
+net_nfc_target_handle_h net_nfc_test_device_get_target_handle(void);
+
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_SE_H__
+#define __NET_NFC_TEST_SE_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_se_send_apdu(gpointer data,
+ gpointer user_data );
+
+void net_nfc_test_se_send_apdu_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_secure_element_type(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_secure_element_type_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_open_internal_secure_element(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_open_internal_secure_element_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_close_internal_secure_element(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_close_internal_secure_element_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_get_atr(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_get_atr_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_event_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_unset_event_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_ese_detection_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_unset_ese_detection_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_set_transaction_event_cb(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_se_unset_transaction_event_cb(gpointer data,
+ gpointer user_data);
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_SNEP_H__
+#define __NET_NFC_TEST_SNEP_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_snep_set_tag_discovered(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_start_server(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_start_server_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_start_client(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_start_client_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_send_client_request(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_send_client_request_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_register_server(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_unregister_server(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_stop_service(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_snep_stop_service_sync(gpointer data,
+ gpointer user_data);
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_TAG_H__
+#define __NET_NFC_TEST_TAG_H__
+
+#include <glib.h>
+
+#include "net_nfc_target_info.h"
+
+void net_nfc_test_tag_is_tag_connected(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_current_tag_info(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_current_target_handle(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_is_tag_connected_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_current_tag_info_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_current_target_handle_sync(gpointer data,
+ gpointer user_data);
+
+/* waiting for signal */
+void net_nfc_test_tag_set_tag_discovered(gpointer data,
+ gpointer user_data);
+
+net_nfc_target_info_h net_nfc_test_tag_get_target_info(void);
+
+void net_nfc_test_tag_set_tag_detached(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_set_filter(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_get_filter(gpointer data,
+ gpointer user_data);
+
+
+#endif //__NET_NFC_TEST_TAG_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_FELICA_TAG_H__
+#define __NET_NFC_TEST_FELICA_TAG_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_felica_poll(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_request_service(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_request_response(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_read_without_encryption(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_write_without_encryption(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_felica_request_system_code(gpointer data,
+ gpointer user_data);
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_TAG_MIFARE_H__
+#define __NET_NFC_TEST_TAG_MIFARE_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_tag_mifare_read(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_authenticate_with_keyA(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_authenticate_with_keyB(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_write_block(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_write_page(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_increment(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_decrement(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_transfer(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_restore(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_create_default_key(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_tag_mifare_create_net_nfc_forum_key(gpointer data,
+ gpointer user_data);
+
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __NET_NFC_TEST_TEST_H__
+#define __NET_NFC_TEST_TEST_H__
+
+#include <glib.h>
+
+void net_nfc_test_test_sim_test(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_prbs_test(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_get_firmware_version(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_set_ee_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_sim_test_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_prbs_test_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_get_firmware_version_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_test_set_ee_data_sync(gpointer data,
+ gpointer user_data);
+
+#endif //__NET_NFC_TEST_TEST_H__
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NET_NFC_TEST_TRANSCEIVE_H__
+#define __NET_NFC_TEST_TRANSCEIVE_H__
+
+#include <glib.h>
+
+
+void net_nfc_test_transceive(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_transceive_sync(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_transceive_data(gpointer data,
+ gpointer user_data);
+
+void net_nfc_test_transceive_data_sync(gpointer data,
+ gpointer user_data);
+
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _NET_NFC_TEST_UTIL_H_
+#define _NET_NFC_TEST_UTIL_H_
+
+#include <glib-object.h>
+#include <string.h>
+#include "net_nfc_data.h"
+
+
+void print_received_data(data_h data);
+
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <glib.h>
+#include <glib-object.h>
+
+#include "net_nfc.h"
+
+#include "net_nfc_test_client.h"
+#include "net_nfc_test_llcp.h"
+#include "net_nfc_test_snep.h"
+#include "net_nfc_test_manager.h"
+#include "net_nfc_test_tag.h"
+#include "net_nfc_test_ndef.h"
+#include "net_nfc_test_test.h"
+#include "net_nfc_test_p2p.h"
+#include "net_nfc_test_handover.h"
+#include "net_nfc_test_transceive.h"
+#include "net_nfc_test_jewel.h"
+#include "net_nfc_test_tag_mifare.h"
+#include "net_nfc_test_tag_felica.h"
+#include "net_nfc_test_exchanger.h"
+#include "net_nfc_test_se.h"
+
+
+typedef struct _TestData TestData;
+
+struct _TestData
+{
+ gchar *interface;
+ gchar *name;
+ GFunc func;
+ GFunc func_sync;
+ gchar *comment;
+};
+
+static TestData test_data[] = {
+ {
+ "Manager",
+ "SetActive",
+ net_nfc_test_manager_set_active,
+ net_nfc_test_manager_set_active_sync,
+ "Set activation",
+ },
+
+ {
+ "Manager",
+ "GetServerState",
+ net_nfc_test_manager_get_server_state,
+ net_nfc_test_manager_get_server_state_sync,
+ "Get server state"
+ },
+
+ {
+ "Client",
+ "ClientInitialize",
+ net_nfc_test_initialize,
+ net_nfc_test_initialize,
+ "Start Client Initialization"
+ },
+
+ {
+ "Client",
+ "ClientDeinitialize",
+ net_nfc_test_deinitialize,
+ net_nfc_test_deinitialize,
+ "Start Client Deinitialization"
+ },
+
+ {
+ "Client",
+ "ClientIsNfcSupported",
+ net_nfc_test_is_nfc_supported,
+ net_nfc_test_is_nfc_supported,
+ "Get is nfc supported"
+ },
+
+ {
+ "Client",
+ "ClientGetNfcState",
+ net_nfc_test_get_nfc_state,
+ net_nfc_test_get_nfc_state,
+ "Get nfc state"
+ },
+
+ {
+ "Tag",
+ "IsTagConnected",
+ net_nfc_test_tag_is_tag_connected,
+ net_nfc_test_tag_is_tag_connected_sync,
+ "Get is tag connected"
+ },
+ {
+ "Tag",
+ "GetCurrentTagInfo",
+ net_nfc_test_tag_get_current_tag_info,
+ net_nfc_test_tag_get_current_tag_info_sync,
+ "Get current tag info"
+ },
+
+ {
+ "Tag",
+ "GetCurrentTargetHandle",
+ net_nfc_test_tag_get_current_target_handle,
+ net_nfc_test_tag_get_current_target_handle_sync,
+ "Get current target handle id"
+ },
+
+ {
+ "Tag",
+ "TagDiscovered", /* waiting for signal */
+ net_nfc_test_tag_set_tag_discovered,
+ net_nfc_test_tag_set_tag_discovered,
+ "Waiting for TagDiscoved signal"
+ },
+
+ {
+ "Tag",
+ "SetFilter",
+ net_nfc_test_tag_set_filter,
+ net_nfc_test_tag_set_filter,
+ "Set Tag filter"
+ },
+
+ {
+ "Tag",
+ "GetFilter",
+ net_nfc_test_tag_get_filter,
+ net_nfc_test_tag_get_filter,
+ "Get Tag filter"
+ },
+
+
+ {
+ "Tag",
+ "TagDetached", /* waiting for signal */
+ net_nfc_test_tag_set_tag_detached,
+ net_nfc_test_tag_set_tag_detached,
+ "Waiting for TagDetached signal"
+ },
+
+ {
+ "Ndef",
+ "Read",
+ net_nfc_test_ndef_read,
+ net_nfc_test_ndef_read_sync,
+ "Read NDEF",
+ },
+
+ {
+ "Ndef",
+ "Write",
+ net_nfc_test_ndef_write,
+ net_nfc_test_ndef_write_sync,
+ "Write NDEF"
+ },
+
+ {
+ "Ndef",
+ "Format",
+ net_nfc_test_ndef_format,
+ net_nfc_test_ndef_format_sync,
+ "Format NDEF"
+ },
+
+ {
+ "Ndef",
+ "MakeReadOnly",
+ net_nfc_test_ndef_make_read_only,
+ net_nfc_test_ndef_make_read_only_sync,
+ "Make Tag Read only"
+ },
+
+ {
+ "Test",
+ "SimTest",
+ net_nfc_test_test_sim_test,
+ net_nfc_test_test_sim_test_sync,
+ "Read SIM test"
+ },
+
+ {
+ "Test",
+ "PrbsTest",
+ net_nfc_test_test_prbs_test,
+ net_nfc_test_test_prbs_test_sync,
+ "PRBS Test"
+ },
+
+ {
+ "Test",
+ "GetFirmwareVersion",
+ net_nfc_test_test_get_firmware_version,
+ net_nfc_test_test_get_firmware_version_sync,
+ "Get firmware veresion"
+ },
+
+ {
+ "Test",
+ "SetEeData",
+ net_nfc_test_test_set_ee_data,
+ net_nfc_test_test_set_ee_data_sync,
+ "Set EEData"
+ },
+
+ {
+ "p2p",
+ "Send",
+ net_nfc_test_p2p_send,
+ net_nfc_test_p2p_send_sync,
+ "P2P Send"
+
+ },
+
+ {
+ "p2p",
+ "Discovered", /* waiting for signal*/
+ net_nfc_test_p2p_set_device_discovered,
+ net_nfc_test_p2p_set_device_discovered,
+ "Waiting for Device Discovered Signal"
+ },
+
+ {
+ "p2p",
+ "Detached", /* waiting for signal*/
+ net_nfc_test_p2p_set_device_detached,
+ net_nfc_test_p2p_set_device_detached,
+ "Waiting for Device Detached Signal"
+ },
+
+ {
+ "p2p",
+ "Received", /* waiting for signal*/
+ net_nfc_test_p2p_set_data_received,
+ net_nfc_test_p2p_set_data_received,
+ "Waiting for Device Data Received Signal"
+ },
+
+ {
+ "Transceive",
+ "TransceiveData",
+ net_nfc_test_transceive_data,
+ net_nfc_test_transceive_data_sync,
+ "Tansceive data method call "
+ },
+
+ {
+ "Transceive",
+ "Transceive",
+ net_nfc_test_transceive,
+ net_nfc_test_transceive_sync,
+ "Tansceive method call"
+ },
+
+ {
+ "Handover",
+ "Request",
+ net_nfc_test_p2p_connection_handover,
+ net_nfc_test_p2p_connection_handover_sync,
+ "Handover Request Call"
+
+ },
+
+ {
+ "Handover",
+ "GetCarrierType",
+ net_nfc_test_handover_get_alternative_carrier_type,
+ net_nfc_test_handover_get_alternative_carrier_type,
+ "Get Handover Carrier Type"
+
+ },
+
+ {
+ "Handover",
+ "GetCarrierData",
+ net_nfc_test_handover_get_alternative_carrier_data,
+ net_nfc_test_handover_get_alternative_carrier_data,
+ "Get Handover Carrier Data"
+
+ },
+
+ {
+ "JewelTag",
+ "ReadId",
+ net_nfc_test_tag_jewel_read_id,
+ net_nfc_test_tag_jewel_read_id,
+ "Jewel Read id"
+
+ },
+
+ {
+ "JewelTag",
+ "ReadByte",
+ net_nfc_test_tag_jewel_read_byte,
+ net_nfc_test_tag_jewel_read_byte,
+ "Jewel Read Byte"
+
+ },
+
+ {
+ "JewelTag",
+ "ReadAll",
+ net_nfc_test_tag_jewel_read_all,
+ net_nfc_test_tag_jewel_read_all,
+ "Jewel Read All"
+
+ },
+
+ {
+ "JewelTag",
+ "WriteWithErase",
+ net_nfc_test_tag_jewel_write_with_erase,
+ net_nfc_test_tag_jewel_write_with_erase,
+ "Jewel Write With Erase"
+
+ },
+
+ {
+ "JewelTag",
+ "WriteWithNoErase",
+ net_nfc_test_tag_jewel_write_with_no_erase,
+ net_nfc_test_tag_jewel_write_with_no_erase,
+ "Jewel Write With No Erase"
+
+ },
+
+ {
+ "MifareTag",
+ "Read",
+ net_nfc_test_tag_mifare_read,
+ net_nfc_test_tag_mifare_read,
+ "Read Mifare Tag"
+ },
+
+ {
+ "MifareTag",
+ "WriteBlock",
+ net_nfc_test_tag_mifare_write_block,
+ net_nfc_test_tag_mifare_write_block,
+ "Write data block"
+ },
+
+ {
+ "MifareTag",
+ "WritePage",
+ net_nfc_test_tag_mifare_write_page,
+ net_nfc_test_tag_mifare_write_page,
+ "Write Page Data"
+ },
+
+ {
+ "MifareTag",
+ "Increment",
+ net_nfc_test_tag_mifare_increment,
+ net_nfc_test_tag_mifare_increment,
+ "Increment block value"
+ },
+
+ {
+ "MifareTag",
+ "Decrement",
+ net_nfc_test_tag_mifare_decrement,
+ net_nfc_test_tag_mifare_decrement,
+ "Decrement block value"
+ },
+
+ {
+ "MifareTag",
+ "Transfer",
+ net_nfc_test_tag_mifare_transfer,
+ net_nfc_test_tag_mifare_transfer,
+ " Data Transfer"
+ },
+
+ {
+ "MifareTag",
+ "Restore",
+ net_nfc_test_tag_mifare_restore,
+ net_nfc_test_tag_mifare_restore,
+ "Data Restore"
+ },
+
+ {
+ "MifareTag",
+ "AuthKeyA",
+ net_nfc_test_tag_mifare_authenticate_with_keyA,
+ net_nfc_test_tag_mifare_authenticate_with_keyA,
+ "Authenticate with key A"
+ },
+
+ {
+ "MifareTag",
+ "AuthKeyB",
+ net_nfc_test_tag_mifare_authenticate_with_keyB,
+ net_nfc_test_tag_mifare_authenticate_with_keyB,
+ "Authenticate with key B"
+ },
+
+ {
+ "FelicaTag",
+ "FelicaPoll",
+ net_nfc_test_felica_poll,
+ net_nfc_test_felica_poll,
+ "Felica Poll"
+ },
+
+ {
+ "FelicaTag",
+ "FelicaRequestService",
+ net_nfc_test_felica_request_service,
+ net_nfc_test_felica_request_service,
+ "Felica Request Service"
+ },
+
+ {
+ "FelicaTag",
+ "FelicaRequestResponse",
+ net_nfc_test_felica_request_response,
+ net_nfc_test_felica_request_response,
+ "Felica Request Response"
+ },
+
+ {
+ "FelicaTag",
+ "FelicaReadWithoutEncryption",
+ net_nfc_test_felica_read_without_encryption,
+ net_nfc_test_felica_read_without_encryption,
+ "Felica Read Without Encryption"
+ },
+
+ {
+ "FelicaTag",
+ "FelicaWriteWithoutEncryption",
+ net_nfc_test_felica_write_without_encryption,
+ net_nfc_test_felica_write_without_encryption,
+ "Felica Write Without Encryption"
+ },
+
+ {
+ "FelicaTag",
+ "FelicaRequestSystemCode",
+ net_nfc_test_felica_request_system_code,
+ net_nfc_test_felica_request_system_code,
+ "Felica Request System Code"
+ },
+
+ {
+ "Exchanger",
+ "CreateData",
+ net_nfc_test_create_exchanger_data,
+ net_nfc_test_create_exchanger_data,
+ "Create exchanger data"
+ },
+
+ {
+ "Exchanger",
+ "SendData",
+ net_nfc_test_send_exchanger_data,
+ net_nfc_test_send_exchanger_data,
+ "Send Exchanger Data"
+ },
+
+ {
+ "Exchanger",
+ "ConnectionHandover",
+ net_nfc_test_exchanger_request_connection_handover,
+ net_nfc_test_exchanger_request_connection_handover,
+ "Request Connection Hnadover"
+ },
+
+ {
+ "Exchanger",
+ "GetCarrierData",
+ net_nfc_test_exchanger_get_alternative_carrier_data,
+ net_nfc_test_exchanger_get_alternative_carrier_data,
+ "Get alternative carrier data"
+ },
+
+ {
+ "Exchanger",
+ "GetCarrierType",
+ net_nfc_test_exchanger_get_alternative_carrier_type,
+ net_nfc_test_exchanger_get_alternative_carrier_type,
+ "Get Alternative carrier type"
+ },
+ {
+ "llcp",
+ "SetDefaultConfig",
+ net_nfc_test_llcp_default_config,
+ net_nfc_test_llcp_default_config_sync,
+ "Set the Default Config Options"
+ },
+
+ {
+ "llcp",
+ "SetCustomConfig",
+ net_nfc_test_llcp_custom_config,
+ net_nfc_test_llcp_custom_config_sync,
+ "Set the Customised Config Options"
+ },
+
+ {
+ "llcp",
+ "GetConfigWKS",
+ net_nfc_test_llcp_get_config_wks,
+ net_nfc_test_llcp_get_config_wks,
+ "Get the Config of WKS"
+ },
+
+
+ {
+ "llcp",
+ "GetConfigLTO",
+ net_nfc_test_llcp_get_config_lto,
+ net_nfc_test_llcp_get_config_lto,
+ "Get the Config of LTO"
+ },
+
+
+ {
+ "llcp",
+ "GetConfigMIU",
+ net_nfc_test_llcp_get_config_miu,
+ net_nfc_test_llcp_get_config_miu,
+ "Get the Config of MIU"
+ },
+
+ {
+ "llcp",
+ "GetConfigOption",
+ net_nfc_test_llcp_get_config_option,
+ net_nfc_test_llcp_get_config_option,
+ "Get the Config Option Type"
+ },
+
+ {
+ "llcp",
+ "SetConfigWKS",
+ net_nfc_test_llcp_set_config_wks,
+ net_nfc_test_llcp_set_config_wks,
+ "Set the Config for WKS"
+ },
+
+
+ {
+ "llcp",
+ "SetConfigLTO",
+ net_nfc_test_llcp_set_config_lto,
+ net_nfc_test_llcp_set_config_lto,
+ "Set the Config for LTO"
+ },
+
+
+ {
+ "llcp",
+ "SetConfigMIU",
+ net_nfc_test_llcp_set_config_miu,
+ net_nfc_test_llcp_set_config_miu,
+ "Set the Config for MIU"
+ },
+
+ {
+ "llcp",
+ "SetConfigOption",
+ net_nfc_test_llcp_set_config_option,
+ net_nfc_test_llcp_set_config_option,
+ "Set the Config Option Type"
+ },
+
+ {
+ "llcp",
+ "FreeConfig",
+ net_nfc_test_llcp_free_config,
+ net_nfc_test_llcp_free_config,
+ "Clear the llcp configuration options"
+ },
+
+
+ {
+ "llcp",
+ "CreateCustomSocketOption",
+ net_nfc_test_llcp_create_custom_socket_option,
+ net_nfc_test_llcp_create_custom_socket_option,
+ "Create Custom Socket Option"
+ },
+
+ {
+ "llcp",
+ "CreateDefaultSocketOption",
+ net_nfc_test_llcp_create_default_socket_option,
+ net_nfc_test_llcp_create_default_socket_option,
+ "Create Default Socket Option"
+ },
+
+
+ {
+ "llcp",
+ "GetLocalSocketOption",
+ net_nfc_test_llcp_get_local_socket_option,
+ net_nfc_test_llcp_get_local_socket_option,
+ "Get Local Socket Option"
+ },
+
+
+ {
+ "llcp",
+ "GetLocalSocketMIU",
+ net_nfc_test_llcp_get_socket_option_miu,
+ net_nfc_test_llcp_get_socket_option_miu,
+ "Get Local Socket MIU"
+ },
+
+
+ {
+ "llcp",
+ "GetLocalSocketRW",
+ net_nfc_test_llcp_get_socket_option_rw,
+ net_nfc_test_llcp_get_socket_option_rw,
+ "Get Local Socket RW"
+ },
+
+
+ {
+ "llcp",
+ "GetLocalSocketOptionType",
+ net_nfc_test_llcp_get_socket_option_type,
+ net_nfc_test_llcp_get_socket_option_type,
+ "Get Local Socket Option Type"
+ },
+
+ {
+ "llcp",
+ "SetLocalSocketMIU",
+ net_nfc_test_llcp_set_socket_option_miu,
+ net_nfc_test_llcp_set_socket_option_miu,
+ "Set Local Socket MIU"
+ },
+
+
+ {
+ "llcp",
+ "SetLocalSocketRW",
+ net_nfc_test_llcp_set_socket_option_rw,
+ net_nfc_test_llcp_set_socket_option_rw,
+ "Set Local Socket RW"
+ },
+
+
+ {
+ "llcp",
+ "SetLocalSocketOptionType",
+ net_nfc_test_llcp_set_socket_option_type,
+ net_nfc_test_llcp_set_socket_option_type,
+ "Set Local Socket Option Type"
+ },
+
+ {
+ "llcp",
+ "FreeSocketOption",
+ net_nfc_test_llcp_free_socket_option,
+ net_nfc_test_llcp_free_socket_option,
+ "Free Socket Option"
+ },
+
+ {
+ "llcp",
+ "ListenToSocket",
+ net_nfc_test_llcp_listen,
+ net_nfc_test_llcp_listen_sync,
+ "Listen To Server Socket"
+ },
+
+ {
+ "llcp",
+ "ReceiveSocket",
+ net_nfc_test_llcp_receive,
+ net_nfc_test_llcp_receive_sync,
+ "Receive data from socket "
+ },
+
+ {
+ "llcp",
+ "ReceiveFromSocket",
+ net_nfc_test_llcp_receive_from,
+ net_nfc_test_llcp_receive_from_sync,
+ "Receive data from socket (sap data also included)"
+ },
+
+ {
+ "llcp",
+ "ConnectToSocket",
+ net_nfc_test_llcp_connect,
+ net_nfc_test_llcp_connect_sync,
+ "Connect to a socket"
+ },
+
+ {
+ "llcp",
+ "ConnectToSapSocket",
+ net_nfc_test_llcp_connect_sap,
+ net_nfc_test_llcp_connect_sap_sync,
+ "Connect to a specific SAP on the socket"
+ },
+
+ {
+ "llcp",
+ "SendToSocket",
+ net_nfc_test_llcp_send,
+ net_nfc_test_llcp_send_sync,
+ "Send Data to a socket"
+ },
+
+ {
+ "llcp",
+ "SendToSapSocket",
+ net_nfc_test_llcp_send_to,
+ net_nfc_test_llcp_send_to_sync,
+ "Send data to a specific SAP on the socket"
+ },
+
+ {
+ "llcp",
+ "DisconnectSocket",
+ net_nfc_test_llcp_disconnect,
+ net_nfc_test_llcp_disconnect_sync,
+ "Disconnects the client socket"
+ },
+
+ {
+ "llcp",
+ "DisconnectOtherSockets",
+ net_nfc_test_llcp_disconnect_server,
+ net_nfc_test_llcp_disconnect_server,
+ "Disconnects the Server and Accepted sockets"
+ },
+
+ {
+ "snep",
+ "SNEPTagDiscovery",
+ net_nfc_test_snep_set_tag_discovered,
+ net_nfc_test_snep_set_tag_discovered,
+ "Discovers the tag/target before starting SNEP operation"
+ },
+
+ {
+ "snep",
+ "StartSNEPServer",
+ net_nfc_test_snep_start_server,
+ net_nfc_test_snep_start_server_sync,
+ "Starts the SNEP server"
+ },
+
+ {
+ "snep",
+ "StartSNEPClient",
+ net_nfc_test_snep_start_client,
+ net_nfc_test_snep_start_client_sync,
+ "Starts the SNEP client"
+ },
+
+ {
+ "snep",
+ "SendClientRequest",
+ net_nfc_test_snep_send_client_request,
+ net_nfc_test_snep_send_client_request_sync,
+ "Sends the SNEP client Request"
+ },
+
+ {
+ "snep",
+ "RegisterServer",
+ net_nfc_test_snep_register_server,
+ net_nfc_test_snep_register_server,
+ "Registers the SNEP server"
+ },
+
+ {
+ "snep",
+ "UnRegisterServer",
+ net_nfc_test_snep_unregister_server,
+ net_nfc_test_snep_unregister_server,
+ "UnRegisters the SNEP server"
+ },
+
+ {
+ "SE",
+ "SendApdu",
+ net_nfc_test_se_send_apdu,
+ net_nfc_test_se_send_apdu_sync,
+ "Secure element send apdu data"
+ },
+
+ {
+ "SE",
+ "SetType",
+ net_nfc_test_se_set_secure_element_type,
+ net_nfc_test_se_set_secure_element_type_sync,
+ "Set secure element type"
+ },
+
+ {
+ "SE",
+ "Open",
+ net_nfc_test_se_open_internal_secure_element,
+ net_nfc_test_se_open_internal_secure_element_sync,
+ "Open internal secure element"
+ },
+
+ {
+ "SE",
+ "Close",
+ net_nfc_test_se_close_internal_secure_element,
+ net_nfc_test_se_close_internal_secure_element_sync,
+ "Close internal secure element"
+ },
+
+ {
+ "SE",
+ "GetAtr",
+ net_nfc_test_se_get_atr,
+ net_nfc_test_se_get_atr_sync,
+ "Get secure element attribute"
+ },
+
+ {
+ "SE",
+ "SetEventCallback",
+ net_nfc_test_se_set_event_cb,
+ net_nfc_test_se_set_event_cb,
+ "Set event callback"
+ },
+
+ {
+ "SE",
+ "UnsetEventCallback",
+ net_nfc_test_se_unset_event_cb,
+ net_nfc_test_se_unset_event_cb,
+ "Unset event callback"
+ },
+
+ {
+ "SE",
+ "SetDetectionCallback",
+ net_nfc_test_se_set_ese_detection_cb,
+ net_nfc_test_se_set_ese_detection_cb,
+ "Set detection callback"
+ },
+
+ {
+ "SE",
+ "UnsetDetectionCallback",
+ net_nfc_test_se_unset_ese_detection_cb,
+ net_nfc_test_se_unset_ese_detection_cb,
+ "Unset detection callback"
+ },
+
+ {
+ "SE",
+ "SetTransactionCallback",
+ net_nfc_test_se_set_transaction_event_cb,
+ net_nfc_test_se_set_transaction_event_cb,
+ "Set transaction callback"
+ },
+
+ {
+ "SE",
+ "UnsetTransactionCallback",
+ net_nfc_test_se_unset_transaction_event_cb,
+ net_nfc_test_se_unset_transaction_event_cb,
+ "Unset transaction callback"
+ },
+
+ { NULL }
+};
+
+
+static GMainLoop *loop = NULL;
+
+static GList *pos = NULL;
+
+static void test_string_free(gpointer data);
+
+static void run_test(void);
+
+static void test_string_free(gpointer data)
+{
+ gchar **strv;
+
+ if (data)
+ {
+ strv = data;
+ g_strfreev(strv);
+ }
+}
+
+static void run_test(void)
+{
+ gchar **strv;
+ gint i = 0;
+
+ if (pos == NULL)
+ return;
+
+ strv = pos->data;
+
+ for (i = 0; test_data[i].interface != NULL; i++)
+ {
+ if (strv[0] == NULL)
+ continue;
+
+ if (strv[1] == NULL)
+ continue;
+
+ if ((strcmp(strv[0], test_data[i].interface) == 0) &&
+ (strcmp(strv[1], test_data[i].name) == 0))
+ {
+ pos = pos->next;
+
+
+ if (strv[2] && strcmp(strv[2], "Sync") == 0)
+ {
+ g_print("run %s.%s(Sync)\n", strv[0], strv[1]);
+ test_data[i].func_sync(NULL,
+ (gpointer)run_test);
+ }
+ else
+ {
+ g_print("run %s.%s\n", strv[0], strv[1]);
+ test_data[i].func(NULL,
+ (gpointer)run_test);
+ }
+
+ break;
+ }
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ gint i;
+
+ g_type_init();
+
+ if (argc == 2 && strcmp(argv[1], "--help") == 0)
+ {
+ g_print("nfc-client-test: nfc-client-test [inteface.name]\n");
+ g_print("\n");
+
+ for (i = 0; i < G_N_ELEMENTS(test_data) - 1; i++)
+ {
+ g_print("\t%s - %s : %s\n", test_data[i].interface,
+ test_data[i].name,
+ test_data[i].comment);
+ }
+ return 0;
+ }
+
+ for (i = 1 ; i < argc ; i++)
+ {
+ gchar **strv;
+
+ strv = g_strsplit(argv[i], ".", 3);
+ pos = g_list_append(pos, strv);
+ }
+
+ if (pos == NULL)
+ {
+ gchar **strv;
+
+ strv = g_strsplit("Manager.SetActive", ".", 3);
+ pos = g_list_append(pos, strv);
+ }
+ else
+ {
+ gchar **strv;
+
+ strv = pos->data;
+
+ if (strcmp(strv[0], "Manager") != 0 ||
+ strcmp(strv[1], "SetActive") != 0)
+ {
+ gchar **manager_strv;
+
+ manager_strv = g_strsplit("Manager.SetActive", ".", 3);
+ pos = g_list_prepend(pos, manager_strv);
+ }
+ }
+
+ net_nfc_client_initialize();
+
+ run_test();
+
+ loop = g_main_loop_new(NULL, FALSE);
+
+ g_main_loop_run(loop);
+
+ net_nfc_client_deinitialize();
+
+ if (pos)
+ g_list_free_full(pos, test_string_free);
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib-object.h>
+#include "net_nfc_test_client.h"
+#include "net_nfc_client_context.h"
+#include "net_nfc_test_client.h"
+#include "net_nfc_typedef_internal.h"
+
+
+void net_nfc_test_initialize()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ result = net_nfc_client_initialize();
+
+ g_print("Client Initialization Completed & Return value is %d\n", result);
+}
+
+void net_nfc_test_deinitialize()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ result = net_nfc_client_deinitialize();
+
+ g_print("Client Deinitialization Completed & Return value is %d\n", result);
+}
+
+void net_nfc_test_is_nfc_supported()
+{
+ int state = 0;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ result = net_nfc_client_is_nfc_supported(&state);
+
+ g_print("Client is_nfc_supported completed & state value is %d\n", state);
+}
+
+void net_nfc_test_get_nfc_state()
+{
+ int state = 0;
+ net_nfc_error_e result = NET_NFC_OK;
+
+ result = net_nfc_client_get_nfc_state(&state);
+
+ g_print("Client get_nfc_state completed & state value is %d\n", state);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_test_p2p.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_client_exchanger.h"
+#include "net_nfc_test_exchanger.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_test_util.h"
+
+static void run_next_callback(gpointer user_data);
+
+static net_nfc_exchanger_data_h _net_nfc_test_create_exchgr_data();
+
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+static net_nfc_exchanger_data_h _net_nfc_test_create_exchgr_data()
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ data_h rawdata = NULL;
+ net_nfc_exchanger_data_h exch_data = NULL;
+
+ net_nfc_create_ndef_message(&msg);
+ net_nfc_create_rawdata_from_ndef_message(msg, &rawdata);
+ if((result = net_nfc_client_create_exchanger_data(&exch_data, rawdata)) != NET_NFC_OK)
+ {
+ net_nfc_free_data(rawdata);
+ g_printerr(" Exchanger data creation failed \n");
+ return NULL;
+ }
+ net_nfc_free_data(rawdata);
+ return exch_data;
+}
+
+void net_nfc_test_create_exchanger_data(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ data_h rawdata = NULL;
+ net_nfc_exchanger_data_h exch_data = NULL;
+
+ net_nfc_create_ndef_message(&msg);
+ net_nfc_create_rawdata_from_ndef_message(msg, &rawdata);
+ if((result = net_nfc_client_create_exchanger_data(&exch_data, rawdata)) != NET_NFC_OK)
+ {
+ net_nfc_free_data(rawdata);
+ g_printerr(" Exchanger data creation failed \n");
+ return;
+ }
+ net_nfc_free_data(rawdata);
+ return;
+}
+
+void net_nfc_test_send_exchanger_data(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ net_nfc_exchanger_data_h exch_data = NULL;
+
+ exch_data = _net_nfc_test_create_exchgr_data();
+ handle = net_nfc_test_device_get_target_handle();
+
+ result = net_nfc_client_send_exchanger_data(exch_data,
+ handle,
+ user_data);
+ g_print("Send exchanger result : %d\n", result);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_exchanger_request_connection_handover(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ net_nfc_target_handle_h handle = NULL;
+
+ handle = net_nfc_test_device_get_target_handle();
+ result = net_nfc_client_exchanger_request_connection_handover(handle, type);
+
+ g_print(" Exchanger request connection handover : %d\n", result);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_exchanger_get_alternative_carrier_type(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_connection_handover_info_h info = NULL;
+ net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ result = net_nfc_client_exchanger_get_alternative_carrier_type(info, &type);
+ g_print(" Exchanger alternative carrier type and result : %d \n %d",type, result);
+}
+
+void net_nfc_test_exchanger_get_alternative_carrier_data(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_connection_handover_info_h info = NULL;
+ data_h data_info = NULL;
+
+ result = net_nfc_client_exchanger_get_alternative_carrier_data(info, &data_info);
+ g_print(" Exchanger alternative carrier result : %d \n",result);
+ print_received_data(data_info);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_client_handover.h"
+#include "net_nfc_test_handover.h"
+#include "net_nfc_test_util.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_typedef.h"
+#include "net_nfc_test_p2p.h"
+
+
+
+static void run_next_callback(gpointer user_data);
+
+static void p2p_connection_handover_cb(net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_h data,
+ void *user_data);
+
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+static void p2p_connection_handover_cb(net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_h data,
+ void *user_data)
+{
+ g_print("Connection handover completed\n");
+
+ print_received_data(data);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_p2p_connection_handover(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ net_nfc_target_handle_h handle = NULL;
+
+ handle = net_nfc_test_device_get_target_handle();
+
+ g_print("handle for handover : %p \n", handle);
+
+ result = net_nfc_client_p2p_connection_handover(
+ handle,
+ type,
+ p2p_connection_handover_cb,
+ user_data);
+}
+
+void net_nfc_test_p2p_connection_handover_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_conn_handover_carrier_type_e type;
+ net_nfc_conn_handover_carrier_type_e out_carrier;
+ data_h out_data = NULL;
+ type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ net_nfc_target_handle_h handle = NULL;
+
+ handle = net_nfc_test_device_get_target_handle();
+
+ result = net_nfc_client_p2p_connection_handover_sync(
+ handle,
+ type,
+ &out_carrier,
+ &out_data);
+
+ g_print("Received out carrier type & carrier type %d, %d\n", out_carrier, type);
+ print_received_data(out_data);
+}
+
+void net_nfc_test_handover_get_alternative_carrier_type(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_conn_handover_carrier_type_e type;
+ net_nfc_connection_handover_info_h info = NULL;
+
+ result = net_nfc_client_handover_get_alternative_carrier_type(
+ (net_nfc_connection_handover_info_h) & info, &type);
+ g_print("Handover alternative carrier type -> %d", type);
+}
+
+void net_nfc_test_handover_get_alternative_carrier_data(gpointer data,
+ gpointer user_data)
+
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_h out_data = NULL;
+ net_nfc_connection_handover_info_h info = NULL;
+
+ result = net_nfc_client_handover_get_alternative_carrier_data(
+ (net_nfc_connection_handover_info_h)&info, &out_data);
+ g_print(" Get alternative carrier data %d", result);
+ print_received_data(out_data);
+
+ g_print("Handover get data carrier data completed\n");
+}
--- /dev/null
+/*
+* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "net_nfc_test_jewel.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_test_util.h"
+#include "net_nfc_client_tag_jewel.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_test_tag.h"
+
+
+static net_nfc_target_handle_h get_handle();
+
+static void run_next_callback(gpointer user_data);
+
+static void jewel_read_cb(net_nfc_error_e result,
+ data_h resp_data,
+ void *user_data);
+;
+static void jewel_write_cb(net_nfc_error_e result,
+ void* user_data);
+
+
+static net_nfc_target_handle_h get_handle()
+{
+ net_nfc_target_info_h info = NULL;
+ net_nfc_target_handle_h handle = NULL;
+
+ info = net_nfc_test_tag_get_target_info();
+
+ net_nfc_get_tag_handle(info, &handle);
+
+ return handle;
+}
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+
+ callback();
+ }
+}
+
+
+/*********************************** Callbacks *************************************/
+
+static void jewel_read_cb(net_nfc_error_e result,
+ data_h resp_data,
+ void *user_data)
+{
+
+ g_print("jewel_read_cb Completed %d\n", result);
+
+ print_received_data(resp_data);
+
+ run_next_callback(user_data);
+}
+
+static void jewel_write_cb(net_nfc_error_e result,
+ void* user_data)
+{
+ g_print("jewel_write_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+
+/*********************************** Function Calls *************************************/
+
+
+void net_nfc_test_tag_jewel_read_id(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+
+ handle = get_handle();
+
+ result = net_nfc_client_jewel_read_id(handle,
+ jewel_read_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_jewel_read_byte(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t block = 0x01;
+ uint8_t byte = 1;
+
+ handle = get_handle();
+
+ result = net_nfc_client_jewel_read_byte(handle,
+ block,
+ byte,
+ jewel_read_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_jewel_read_all(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+
+ handle = get_handle();
+
+ result = net_nfc_client_jewel_read_all(handle,
+ jewel_read_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_jewel_write_with_erase(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t block = 0x01;
+ uint8_t byte = 1;
+ uint8_t data_to_write = 'A';
+
+ handle = get_handle();
+
+ result = net_nfc_client_jewel_write_with_erase(handle,
+ block,
+ byte,
+ data_to_write,
+ jewel_write_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_jewel_write_with_no_erase(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t block = 0x01;
+ uint8_t byte = 1;
+ uint8_t data_to_write = 'A';
+
+ handle = get_handle();
+
+ result = net_nfc_client_jewel_write_with_erase(handle,
+ block,
+ byte,
+ data_to_write,
+ jewel_write_cb,
+ user_data);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_test_util.h"
+#include "net_nfc_client_llcp.h"
+#include "net_nfc_test_llcp.h"
+#include "net_nfc_data.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_typedef_internal.h"
+
+
+static net_nfc_llcp_socket_t server_test_socket;
+static net_nfc_llcp_socket_t client_test_socket;
+
+static net_nfc_llcp_config_info_h llcp_config = NULL;
+static net_nfc_llcp_config_info_h llcp_config_sync = NULL;
+static net_nfc_llcp_config_info_h llcp_config_default = NULL;
+static net_nfc_llcp_config_info_h llcp_config_default_sync = NULL;
+
+
+/*********************************** utility Calls *************************************/
+
+static void run_next_callback(gpointer user_data);
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+/*********************************** Callbacks *************************************/
+
+static void llcp_default_config_cb(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print(" llcp_default_config_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void llcp_custom_config_cb(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print("llcp_custom_config_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void llcp_listen_socket_cb(net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
+{
+
+ g_print("llcp_listen_socket_cb Completed %d\n", client_socket);
+ g_print("llcp_listen_socket_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void llcp_receive_socket_cb(net_nfc_error_e result,
+ data_h data,
+ void *user_data)
+{
+ data_h received_data = data;
+
+ print_received_data(received_data);
+
+ g_print("llcp_listen_socket_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void llcp_receive_from_socket_cb(net_nfc_error_e result,
+ sap_t sap,
+ data_h data,
+ void *user_data)
+{
+ data_h received_data = data;
+
+ print_received_data(received_data);
+
+ g_print("llcp_receive_from_socket_cb Completed %d\n", sap);
+
+ g_print("llcp_receive_from_socket_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+
+static void llcp_connect_socket_cb(net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
+{
+ g_print("llcp_connect_socket_cb Completed %d\n", client_socket);
+ g_print("llcp_connect_socket_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+
+static void llcp_connect_sap_cb(net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
+{
+ g_print("llcp_connect_socket_cb Completed %d\n", client_socket);
+ g_print("llcp_connect_socket_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+
+static void llcp_send_socket_cb(net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
+{
+ g_print("llcp_send_socket_cb Completed %d\n", client_socket);
+ g_print("llcp_send_socket_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+
+}
+
+static void llcp_send_to_socket_cb(net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
+{
+ g_print("llcp_send_to_socket_cb Completed %d\n", client_socket);
+ g_print("llcp_send_to_socket_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+
+}
+
+static void llcp_disconnect_socket_cb(net_nfc_error_e result,
+ net_nfc_llcp_socket_t client_socket,
+ void *user_data)
+{
+ g_print("llcp_send_to_socket_cb Completed %d\n", client_socket);
+ g_print("llcp_send_to_socket_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+
+}
+
+
+/*********************************** Function Calls *************************************/
+
+void net_nfc_test_llcp_default_config(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_create_config_default(&llcp_config_default);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" llcp create default config failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+
+ }
+ result = net_nfc_client_llcp_config(llcp_config_default,
+ llcp_default_config_cb,
+ user_data);
+
+}
+
+void net_nfc_test_llcp_default_config_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_create_config_default(&llcp_config_default_sync);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" llcp create default config failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+
+ }
+
+ result = net_nfc_client_llcp_config_sync(llcp_config_default_sync);
+ if(result == NET_NFC_OK)
+ {
+ g_print(" llcp create default config (sync) success: %d\n", result);
+ }
+
+}
+
+
+void net_nfc_test_llcp_custom_config(gpointer data,
+ gpointer user_data)
+{
+
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_create_config(&llcp_config,128, 1, 10, 0);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" llcp create custom config failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+
+ }
+ result = net_nfc_client_llcp_config(llcp_config,
+ llcp_custom_config_cb,
+ user_data);
+
+}
+
+
+
+void net_nfc_test_llcp_custom_config_sync(gpointer data,
+ gpointer user_data)
+{
+
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_create_config(&llcp_config_sync,128, 1, 10, 0);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_custom_config_sync failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+
+ }
+ result = net_nfc_client_llcp_config_sync(llcp_config_sync);
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_custom_config_sync (sync) success: %d\n", result);
+ }
+
+}
+
+void net_nfc_test_llcp_get_local_config(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_config_info_h local_config;
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_get_local_config(&local_config);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" llcp create custom config failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+
+ }
+
+ g_print(" net_nfc_test_llcp_get_local_config: %d\n", local_config->miu);
+ g_print("net_nfc_test_llcp_get_local_config: %d\n", local_config->wks);
+ g_print(" net_nfc_test_llcp_get_local_config: %d\n", local_config->lto);
+ g_print("net_nfc_test_llcp_get_local_config: %d\n", local_config->option);
+
+}
+
+
+/*commented because remote config API is not available*/
+/*
+void net_nfc_test_llcp_get_remote_config(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_config_info_h local_config;
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_get_local_config(&local_config);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" llcp create custom config failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+
+ }
+
+ g_print(" net_nfc_test_llcp_get_local_config: %d\n", local_config->miu);
+ g_print("net_nfc_test_llcp_get_local_config: %d\n", local_config->wks);
+ g_print(" net_nfc_test_llcp_get_local_config: %d\n", local_config->lto);
+ g_print("net_nfc_test_llcp_get_local_config: %d\n", local_config->option);
+
+}
+*/
+
+void net_nfc_test_llcp_get_config_miu(gpointer data,
+ gpointer user_data)
+{
+
+ net_nfc_error_e result;
+ uint16_t miu;
+
+ result = net_nfc_client_llcp_get_config_miu(llcp_config,&miu);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_config_miu failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_config_miu ->: %d\n", miu);
+ }
+
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_get_config_wks(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ uint16_t wks;
+
+ result = net_nfc_client_llcp_get_config_wks(llcp_config,&wks);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_config_wks failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_config_wks -> %d\n",wks);
+ }
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_llcp_get_config_lto(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ uint8_t lto;
+
+ result = net_nfc_client_llcp_get_config_lto(llcp_config,<o);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_client_llcp_get_config_lto failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_client_llcp_get_config_lto -> %d\n",lto);
+ }
+
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_get_config_option(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ uint8_t option;
+
+ result = net_nfc_client_llcp_get_config_option(llcp_config,&option);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_config_option failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_config_option -> %d\n",option);
+ }
+
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_set_config_miu(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ uint16_t miu = 128;
+
+ result = net_nfc_client_llcp_set_config_miu(llcp_config,miu);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_config_miu failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_config_miu successfull \n");
+ }
+
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_set_config_wks(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ uint16_t wks = 1;
+
+ result = net_nfc_client_llcp_set_config_wks(llcp_config,wks);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_config_wks failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_config_wks successfull \n");
+ }
+
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_set_config_lto(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ uint16_t lto = 10;
+
+ result = net_nfc_client_llcp_set_config_lto(llcp_config,lto);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_config_lto failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_config_lto successfull \n");
+ }
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_set_config_option(gpointer data,
+ gpointer user_data)
+{
+
+ net_nfc_error_e result;
+ uint8_t option = 0;
+
+ result = net_nfc_client_llcp_set_config_lto(llcp_config,option);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_config_option failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_config_option successfull \n");
+ }
+ run_next_callback(user_data);
+}
+
+
+void net_nfc_test_llcp_free_config(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_free_config(llcp_config);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_free_config failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ if(result == NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_free_config successfull \n");
+ }
+ run_next_callback(user_data);
+}
+
+
+void net_nfc_test_llcp_create_custom_socket_option(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_h option;
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_create_socket_option(&option,
+ 128,
+ 1,
+ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_client_llcp_create_socket_option failed: %d\n", result);
+ run_next_callback(user_data);
+
+ return;
+ }
+
+ g_print(" net_nfc_client_llcp_create_socket_option : %d\n", result);
+ run_next_callback(user_data);
+
+}
+
+void net_nfc_test_llcp_create_default_socket_option(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_h option;
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_create_socket_option_default(&option);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_create_default_socket_option failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_create_default_socket_option : %d\n", result);
+ run_next_callback(user_data);
+
+}
+
+void net_nfc_test_llcp_get_local_socket_option(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_option_h option;
+
+ result = net_nfc_client_llcp_get_local_socket_option(client_test_socket,&option);
+
+if(result != NET_NFC_OK)
+{
+ g_print(" net_nfc_test_llcp_get_local_socket_option failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+}
+
+g_print(" net_nfc_test_llcp_get_local_socket_option: %d\n", option->miu);
+g_print("net_nfc_test_llcp_get_local_socket_option: %d\n", option->rw);
+g_print(" net_nfc_test_llcp_get_local_socket_option: %d\n", option->type);
+
+run_next_callback(user_data);
+
+
+}
+
+void net_nfc_test_llcp_get_socket_option_miu(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_s option;
+ net_nfc_error_e result;
+ uint16_t miu;
+
+ result = net_nfc_client_llcp_get_socket_option_miu(&option,&miu);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_client_llcp_get_socket_option_miu failed: %d\n", result);
+ run_next_callback(user_data);
+
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_get_socket_option_miu : %d\n", miu);
+ run_next_callback(user_data);
+}
+
+
+void net_nfc_test_llcp_set_socket_option_miu(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_s option;
+ net_nfc_error_e result;
+ uint16_t miu = 128;
+
+ result = net_nfc_client_llcp_set_socket_option_miu(&option,miu);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_socket_option_miu failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_set_socket_option_miu : %d\n", miu);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_llcp_get_socket_option_rw(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_s option;
+ net_nfc_error_e result;
+ uint8_t rw;
+
+ result = net_nfc_client_llcp_get_socket_option_rw(&option,&rw);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_socket_option_rw failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_get_socket_option_rw : %d\n", rw);
+ run_next_callback(user_data);
+}
+
+
+void net_nfc_test_llcp_set_socket_option_rw(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_s option;
+ net_nfc_error_e result;
+ uint8_t rw = 1;
+
+ result = net_nfc_client_llcp_set_socket_option_rw(&option,rw);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_socket_option_rw failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_set_socket_option_rw : %d\n", rw);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_llcp_get_socket_option_type(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_s option;
+ net_nfc_error_e result;
+ net_nfc_socket_type_e type;
+
+ result = net_nfc_client_llcp_get_socket_option_type(&option,&type);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_get_socket_option_type failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_get_socket_option_type : %d\n", type);
+ run_next_callback(user_data);
+}
+
+
+void net_nfc_test_llcp_set_socket_option_type(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_s option;
+ net_nfc_error_e result;
+ net_nfc_socket_type_e type = NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED;
+
+ result = net_nfc_client_llcp_set_socket_option_type(&option,type);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_set_socket_option_type failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_set_socket_option_type : %d\n", type);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_llcp_free_socket_option(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_llcp_socket_option_s option;
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_free_socket_option(&option);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_free_socket_option failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_free_socket_option : %d\n", result);
+ run_next_callback(user_data);
+}
+
+
+void net_nfc_test_llcp_listen(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ net_nfc_client_llcp_create_socket(&server_test_socket,NULL);
+
+ result = net_nfc_client_llcp_listen(server_test_socket,
+ "urn:nfc:xsn:samsung.com:testllcp" ,
+ 16 ,
+ llcp_listen_socket_cb,
+ NULL);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_client_llcp_listen failed: %d\n", result);
+ return;
+ }
+}
+
+void net_nfc_test_llcp_listen_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t out_socket;
+
+ net_nfc_client_llcp_create_socket(&server_test_socket,NULL);
+
+ result = net_nfc_client_llcp_listen_sync(server_test_socket,
+ "urn:nfc:xsn:samsung.com:testllcp" ,
+ 16 ,
+ &out_socket);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_listen_sync failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_listen_sync : out_socket %d\n", out_socket);
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_receive(gpointer data,
+ gpointer user_data)
+{
+
+ net_nfc_error_e result;
+
+
+ result = net_nfc_client_llcp_receive(server_test_socket,
+ 512,
+ llcp_receive_socket_cb,
+ NULL);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_client_llcp_listen failed: %d\n", result);
+ return;
+ }
+}
+
+
+void net_nfc_test_llcp_receive_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ data_h out_data;
+
+
+ result = net_nfc_client_llcp_receive_sync(server_test_socket,
+ 512,
+ &out_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_client_llcp_listen failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ print_received_data(out_data);
+ run_next_callback(user_data);
+}
+
+
+
+void net_nfc_test_llcp_receive_from(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+
+ result = net_nfc_client_llcp_receive_from(server_test_socket,
+ 512,
+ llcp_receive_from_socket_cb,
+ NULL);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_receive_from failed: %d\n", result);
+ return;
+ }
+}
+
+void net_nfc_test_llcp_receive_from_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ data_h out_data;
+ sap_t sap_data;
+
+ result = net_nfc_client_llcp_receive_from_sync(server_test_socket,
+ 512,
+ &sap_data,
+ &out_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_client_llcp_listen failed: %d\n", result);
+ return;
+ }
+
+ print_received_data(out_data);
+ g_print(" net_nfc_test_llcp_receive_from_sync : %d\n", result);
+ g_print(" net_nfc_test_llcp_receive_from_sync : %d\n", sap_data);
+ run_next_callback(user_data);
+}
+
+
+
+void net_nfc_test_llcp_connect(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
+
+ result = net_nfc_client_llcp_connect(client_test_socket,
+ "urn:nfc:xsn:samsung.com:testllcp",
+ llcp_connect_socket_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_connect failed: %d\n", result);
+ return;
+ }
+
+}
+
+void net_nfc_test_llcp_connect_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t out_socket;
+
+ net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
+
+ result = net_nfc_client_llcp_connect_sync(client_test_socket,
+ "urn:nfc:xsn:samsung.com:testllcp",
+ &out_socket);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_connect_sync failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_connect_sync : out_socket %d\n", out_socket);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_llcp_connect_sap(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
+
+ result = net_nfc_client_llcp_connect_sap(client_test_socket,
+ 16,
+ llcp_connect_sap_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_connect_sap failed: %d\n", result);
+ return;
+ }
+
+}
+
+void net_nfc_test_llcp_connect_sap_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t out_socket;
+
+ net_nfc_client_llcp_create_socket(&client_test_socket, NULL);
+
+ result = net_nfc_client_llcp_connect_sap_sync(client_test_socket,
+ 16,
+ &out_socket);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_connect_sap_sync failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_connect_sap_sync : out_socket %d\n", out_socket);
+ run_next_callback(user_data);
+}
+
+
+
+void net_nfc_test_llcp_send(gpointer func_data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ data_h data;
+ char * str = "Client message: Hello, server!";
+
+ net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
+
+ result = net_nfc_client_llcp_send(client_test_socket,
+ data,
+ llcp_send_socket_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_send failed: %d\n", result);
+ return;
+ }
+
+}
+
+
+void net_nfc_test_llcp_send_sync(gpointer func_data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ data_h data;
+ char * str = "Client message: Hello, server!";
+ net_nfc_llcp_socket_t out_socket;
+
+ net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
+
+ result = net_nfc_client_llcp_send_sync(client_test_socket,
+ data,
+ &out_socket);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_connect failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_send_sync out_socket: %d\n", out_socket);
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_send_to(gpointer func_data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ data_h data;
+ char * str = "Client message: Hello, server!";
+
+ net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
+
+ result = net_nfc_client_llcp_send_to(client_test_socket,
+ 16,
+ data,
+ llcp_send_to_socket_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_send_to failed: %d\n", result);
+ return;
+ }
+
+}
+
+
+void net_nfc_test_llcp_send_to_sync(gpointer func_data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ data_h data;
+ char * str = "Client message: Hello, server!";
+ net_nfc_llcp_socket_t out_socket;
+
+ net_nfc_create_data (&data, (const uint8_t*)str ,strlen (str) + 1);
+
+ result = net_nfc_client_llcp_send_to_sync(client_test_socket,
+ 16,
+ data,
+ &out_socket);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_send_to_sync failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_send_to_sync out_socket: %d\n", out_socket);
+ run_next_callback(user_data);
+
+}
+
+
+void net_nfc_test_llcp_disconnect(gpointer func_data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_disconnect(client_test_socket,
+ llcp_disconnect_socket_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_disconnect failed: %d\n", result);
+ return;
+ }
+
+}
+
+void net_nfc_test_llcp_disconnect_server(gpointer func_data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_client_llcp_disconnect(server_test_socket,
+ llcp_disconnect_socket_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_disconnect accepted_socket failed: %d\n", result);
+ return;
+ }
+
+}
+
+
+void net_nfc_test_llcp_disconnect_sync(gpointer func_data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ net_nfc_llcp_socket_t out_socket;
+
+ result = net_nfc_client_llcp_disconnect_sync(client_test_socket,
+ &out_socket);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_llcp_disconnect_sync failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_llcp_disconnect_sync out_socket: %d\n", out_socket);
+ run_next_callback(user_data);
+
+}
+
+
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib-object.h>
+
+#include "net_nfc_client_manager.h"
+#include "net_nfc_typedef_internal.h"
+
+static void run_next_callback(gpointer user_data);
+
+static void print_server_state(gint state);
+
+static void set_activated_cb(bool state,
+ void *user_data);
+
+static void set_active_completed_cb(net_nfc_error_e result,
+ void *user_data);
+
+static void get_server_state_completed_cb(net_nfc_error_e result,
+ unsigned int state,
+ void *user_data);
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+static void print_server_state(gint state)
+{
+ if (state == 0)
+ g_print(" --- state : Unknown(%d)\n", state);
+ else
+ {
+ g_print(" --- state :\n");
+ if (state & NET_NFC_SERVER_DISCOVERY)
+ g_print("\tNET_NFC_SERVER_DISCOVERY(%d)\n", state);
+ if (state & NET_NFC_TAG_CONNECTED)
+ g_print("\tNET_NFC_TAG_CONNECTED(%d)\n", state);
+ if (state & NET_NFC_SE_CONNECTION)
+ g_print("\tNET_NFC_SE_CONNECTED(%d)\n", state);
+ if (state & NET_NFC_SNEP_CLIENT_CONNECTED)
+ {
+ g_print("\tNET_NFC_SNEP_CLIENT_CONNECTED(%d)\n",
+ state);
+ }
+ if (state & NET_NFC_NPP_CLIENT_CONNECTED)
+ g_print("\tNET_NFC_NPP_CLIENT_CONNECTED(%d)\n", state);
+ if (state & NET_NFC_SNEP_SERVER_CONNECTED)
+ g_print("\tNET_NFC_SNEP_SERVER_CONNECTED(%d)\n", state);
+ if (state & NET_NFC_NPP_SERVER_CONNECTED)
+ g_print("\tNET_NFC_NPP_SERVER_CONNECTED(%d)\n", state);
+ }
+}
+
+static void set_activated_cb(bool state,
+ void *user_data)
+{
+ g_print("Activated state %d\n", state);
+}
+
+static void set_active_completed_cb(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print("SetActive Completed %d\n", result);
+ run_next_callback(user_data);
+}
+
+static void get_server_state_completed_cb(net_nfc_error_e result,
+ unsigned int state,
+ void *user_data)
+{
+ g_print("GetServerState Completed %d\n", result);
+
+ print_server_state(state);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_manager_set_active(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_manager_set_activated(set_activated_cb, NULL);
+
+ net_nfc_client_manager_set_active(1,
+ set_active_completed_cb,
+ user_data);
+}
+
+void net_nfc_test_manager_get_server_state(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_manager_get_server_state(get_server_state_completed_cb,
+ user_data);
+}
+
+void net_nfc_test_manager_set_active_sync(gpointer data,
+ gpointer user_data)
+{
+ gint i;
+
+ i = net_nfc_client_manager_set_active_sync(1);
+
+ g_print("Return %d\n", i);
+
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+
+ callback();
+ }
+}
+
+void net_nfc_test_manager_get_server_state_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ guint state = 0;
+
+ result = net_nfc_client_manager_get_server_state_sync(&state);
+
+ g_print("GetServerState: %d\n", result);
+
+ print_server_state(state);
+
+ run_next_callback(user_data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_client_ndef.h"
+
+#include "net_nfc_test_tag.h"
+#include "net_nfc_test_ndef.h"
+#include "net_nfc_test_util.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_ndef_record.h"
+#include "net_nfc_test_util.h"
+
+
+static void run_next_callback(gpointer user_data);
+
+static void print_record_well_known_type(ndef_record_h record);
+
+static void print_record(ndef_record_h record);
+
+static void print_ndef_message(ndef_message_h message);
+
+static net_nfc_target_handle_h ndef_get_handle(void);
+
+static ndef_message_h create_ndef_message_text(const gchar *str,
+ const gchar *lang,
+ net_nfc_encode_type_e encode);
+
+static void set_string(const gchar *str);
+
+static gchar *get_write_string(void);
+
+
+static void ndef_read_cb(net_nfc_error_e result,
+ ndef_message_h message,
+ void *user_data);
+
+static void ndef_write_cb(net_nfc_error_e result,
+ void *user_data);
+
+static void ndef_make_read_only_cb(net_nfc_error_e result,
+ void *user_data);
+
+static void ndef_format_cb(net_nfc_error_e result,
+ void *user_data);
+
+static gchar *ndef_str = NULL;
+static gint ndef_count = 0;
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+
+ callback();
+ }
+}
+
+static void print_record_well_known_type(ndef_record_h record)
+{
+ gchar *uri = NULL;
+ gchar *lang = NULL;
+ gchar *text = NULL;
+
+ net_nfc_encode_type_e enc;
+
+ net_nfc_create_uri_string_from_uri_record(record, &uri);
+ if (uri)
+ {
+ g_print("URI: %s\n", uri);
+ g_free(uri);
+ }
+
+ net_nfc_create_text_string_from_text_record(record, &text);
+ if(text)
+ {
+ g_print("Text:\n%s\n", text);
+ set_string(text);
+ g_free(text);
+
+ }
+
+ net_nfc_get_languange_code_string_from_text_record(record, &lang);
+ if(lang)
+ {
+ g_print("Language: %s\n", lang);
+ g_free(lang);
+ }
+
+ net_nfc_get_encoding_type_from_text_record(record, &enc);
+ switch (enc)
+ {
+ case NET_NFC_ENCODE_UTF_8:
+ g_print("Encoding: UTF-8\n");
+ break;
+ case NET_NFC_ENCODE_UTF_16:
+ g_print("Encoding: UTF-16\n");
+ break;
+ default:
+ g_print("Encoding: Unknown\n");
+ }
+}
+
+static void print_record(ndef_record_h record)
+{
+ guint8 flag;
+ gchar *str = NULL;
+
+ gchar *tnf_str[] = {
+ "Empty",
+ "Well-known type",
+ "Media-type",
+ "Absolute URI",
+ "External type",
+ "Unknown",
+ "Unchanged"
+ };
+
+ net_nfc_record_tnf_e tnf;
+
+ data_h type = NULL;
+ data_h id = NULL;
+ data_h payload = NULL;
+
+ net_nfc_get_record_flags(record, &flag);
+ net_nfc_get_record_tnf(record, &tnf);
+
+ g_print("MB: %d ME: %d CF: %d SR: %d IL: %d TNF: %s\n",
+ net_nfc_get_record_mb(flag),
+ net_nfc_get_record_me(flag),
+ net_nfc_get_record_cf(flag),
+ net_nfc_get_record_sr(flag),
+ net_nfc_get_record_il(flag),
+ tnf_str[tnf]);
+
+ net_nfc_get_record_type(record, &type);
+
+ str = g_strndup((gchar *)net_nfc_get_data_buffer(type),
+ net_nfc_get_data_length(type));
+ g_print("Type : %s\n", str);
+ g_free(str);
+
+ net_nfc_get_record_id(record, &id);
+
+ str = g_strndup((gchar *)net_nfc_get_data_buffer(id),
+ net_nfc_get_data_length(id));
+ g_print("ID : %s\n", str);
+ g_free(str);
+
+ net_nfc_get_record_payload(record, &payload);
+ print_received_data(payload);
+
+ switch(tnf)
+ {
+ case NET_NFC_RECORD_EMPTY:
+ break;
+ case NET_NFC_RECORD_WELL_KNOWN_TYPE:
+ print_record_well_known_type(record);
+ break;
+ case NET_NFC_RECORD_MIME_TYPE:
+ break;
+ case NET_NFC_RECORD_URI:
+ break;
+ case NET_NFC_RECORD_EXTERNAL_RTD:
+ break;
+ case NET_NFC_RECORD_UNKNOWN:
+ break;
+ case NET_NFC_RECORD_UNCHAGNED:
+ break;
+ default:
+ g_print("TNF: unknown error\n");
+ break;
+ }
+}
+
+static void print_ndef_message(ndef_message_h message)
+{
+ gint count = 0;
+ gint i;
+
+ if (message == NULL)
+ {
+ g_print("Empty ndef message\n");
+ return;
+ }
+
+ if (net_nfc_get_ndef_message_record_count(message,
+ &count) != NET_NFC_OK)
+ {
+ g_print("can not get count of record\n");
+ return;
+ }
+
+ for (i = 0; i < count; i++)
+ {
+ ndef_record_h record = NULL;
+
+ g_print("Record count : %d\n", i+1);
+
+ if (net_nfc_get_record_by_index(message,
+ i,
+ &record) != NET_NFC_OK)
+ {
+ g_print("can not get record from index %d\n", i);
+ continue;
+ }
+
+ print_record(record);
+ }
+
+ g_print("\n");
+}
+
+static net_nfc_target_handle_h ndef_get_handle(void)
+{
+ net_nfc_target_info_h info;
+ net_nfc_target_handle_h handle;
+
+ bool is_ndef = false;
+
+ info = net_nfc_test_tag_get_target_info();
+ if (info == NULL)
+ {
+ g_print("net_nfc_target_info_h is NULL\n");
+ return NULL;
+ }
+
+ net_nfc_get_tag_ndef_support(info, &is_ndef);
+
+ if (is_ndef == false)
+ {
+ g_print("Tag does not support NDEF\n");
+ return NULL;
+ }
+
+ net_nfc_get_tag_handle(info, &handle);
+
+ return handle;
+}
+
+static ndef_message_h create_ndef_message_text(const gchar *str,
+ const gchar *lang,
+ net_nfc_encode_type_e encode)
+{
+ ndef_record_h record = NULL;
+ ndef_message_h message = NULL;
+
+ if (net_nfc_create_ndef_message(&message) != NET_NFC_OK)
+ {
+ g_printerr("Can not create ndef message\n");
+ return NULL;
+ }
+
+ if (net_nfc_create_text_type_record(&record,
+ str,
+ lang,
+ encode) != NET_NFC_OK)
+ {
+ g_printerr("Can not create text record(%s, %d): %s\n",
+ lang, encode, str);
+
+ net_nfc_free_ndef_message(message);
+ return NULL;
+ }
+
+ if (net_nfc_append_record_to_ndef_message(message,
+ record) != NET_NFC_OK)
+ {
+ g_printerr("Can not append record to message\n");
+ net_nfc_free_ndef_message(message);
+ }
+
+ return message;
+}
+
+static void set_string(const gchar *str)
+{
+ gint count = 0;
+
+ if (str == NULL)
+ return;
+
+ sscanf(str, "Count: %d", &count);
+
+ if (count == 0)
+ ndef_str = g_strdup(str);
+ else
+ {
+ gchar *tmp;
+ gchar *pos;
+
+ pos = (gchar *)str;
+ tmp = g_strdup_printf("Count: %d", count);
+ if (strncmp(pos, tmp, strlen(tmp)) == 0)
+ {
+ if (*pos == ' ')
+ pos++;
+
+ ndef_str = g_strdup(pos + strlen(tmp));
+ }
+
+ g_free(tmp);
+ }
+
+ ndef_count = count;
+}
+
+static gchar *get_write_string(void)
+{
+ gchar *str = NULL;
+
+ ndef_count++;
+
+ if (ndef_str == NULL)
+ str = g_strdup_printf("Count: %d", ndef_count);
+ else
+ str = g_strdup_printf("Count: %d %s", ndef_count, ndef_str);
+
+ return str;
+}
+
+static void ndef_read_cb(net_nfc_error_e result,
+ ndef_message_h message,
+ void *user_data)
+{
+ g_print("Read NDEF Completed %d\n", result);
+
+ print_ndef_message(message);
+
+ run_next_callback(user_data);
+}
+
+static void ndef_write_cb(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print("Write NDEF Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+
+static void ndef_make_read_only_cb(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print("Make Read only Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void ndef_format_cb(net_nfc_error_e result,
+ void *user_data)
+
+{
+ g_print("NDEF Format Completed: %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+
+
+void net_nfc_test_ndef_read(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_target_handle_h handle;
+
+ handle = ndef_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+
+ return;
+ }
+
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ net_nfc_client_ndef_read(handle,
+ ndef_read_cb,
+ user_data);
+}
+
+void net_nfc_test_ndef_write(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_target_handle_h handle;
+ ndef_message_h message;
+
+ gchar *str = NULL;
+
+ handle = ndef_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ str = get_write_string();
+ if(str == NULL)
+ {
+ g_printerr("Can not get write string\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+
+ message = create_ndef_message_text(str,
+ "en-US",
+ NET_NFC_ENCODE_UTF_8);
+
+ g_free(str);
+
+ if (message == NULL)
+ {
+ g_printerr("message is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+
+ net_nfc_client_ndef_write(handle,
+ message,
+ ndef_write_cb,
+ user_data);
+
+}
+
+void net_nfc_test_ndef_make_read_only(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_target_handle_h handle;
+
+ handle = ndef_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ net_nfc_client_ndef_make_read_only(handle,
+ ndef_make_read_only_cb,
+ user_data);
+}
+
+void net_nfc_test_ndef_format(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_target_handle_h handle;
+ data_h key;
+ guint8 format_data[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+ handle = ndef_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+
+ net_nfc_create_data(&key, format_data, 6);
+
+ net_nfc_client_ndef_format(handle,
+ key,
+ ndef_format_cb,
+ user_data);
+
+ net_nfc_free_data(key);
+
+ return;
+}
+
+void net_nfc_test_ndef_read_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_target_handle_h handle;
+ ndef_message_h message = NULL;
+ net_nfc_error_e result;
+
+ handle = ndef_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ result = net_nfc_client_ndef_read_sync(handle,
+ &message);
+
+ g_print("Read Ndef: %d\n", result);
+
+ print_ndef_message(message);
+
+ net_nfc_free_ndef_message(message);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_ndef_write_sync(gpointer data,
+ gpointer user_data)
+{
+ gchar *str = NULL;
+
+ net_nfc_target_handle_h handle;
+ ndef_message_h message;
+ net_nfc_error_e result;
+
+ handle = ndef_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ str = get_write_string();
+ if(str == NULL)
+ {
+ g_printerr("Can not get write string\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+
+ message = create_ndef_message_text(str,
+ "en-US",
+ NET_NFC_ENCODE_UTF_8);
+
+ g_free(str);
+
+ if (message == NULL)
+ {
+ g_printerr("message is NULL\n");
+
+ run_next_callback(user_data);
+
+ return;
+ }
+
+ result = net_nfc_client_ndef_write_sync(handle, message);
+
+ g_print("Write Ndef: %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_ndef_make_read_only_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_target_handle_h handle;
+ net_nfc_error_e result;
+
+ handle = ndef_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+
+ return;
+ }
+
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ result = net_nfc_client_ndef_make_read_only_sync(handle);
+
+ g_print("Make Read Only: %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_ndef_format_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_target_handle_h handle;
+ net_nfc_error_e result;
+ data_h key;
+ guint8 format_data[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+ handle = ndef_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+
+ return;
+ }
+
+ net_nfc_create_data(&key, format_data, 6);
+
+ result = net_nfc_client_ndef_format_sync(handle, key);
+
+ net_nfc_free_data(key);
+
+ g_print("NDEF Format %d\n", result);
+
+ run_next_callback(user_data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_client_p2p.h"
+#include "net_nfc_client_exchanger.h"
+#include "net_nfc_test_p2p.h"
+#include "net_nfc_test_util.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_ndef_record.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_typedef.h"
+
+
+static net_nfc_target_handle_h global_handle = NULL;
+
+static void run_next_callback(gpointer user_data);
+
+static void p2p_send(net_nfc_error_e result,
+ void *user_data);
+
+static void p2p_device_discovered(net_nfc_target_handle_h handle,
+ void *user_data);
+
+
+static void p2p_device_detached(void * user_data);
+
+static void p2p_device_data_received(data_h p2p_data, void *user_data);
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+
+ callback();
+ }
+}
+
+static void p2p_send(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print("P2P send Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void p2p_device_discovered(net_nfc_target_handle_h handle,
+ void *user_data)
+{
+ g_print("Target is Discovered\n");
+ global_handle = handle;
+
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(global_handle));
+ run_next_callback(user_data);
+}
+
+static void p2p_device_detached(void * user_data)
+{
+ g_print("Target is detached\n");
+
+ run_next_callback(user_data);
+}
+
+static void p2p_device_data_received(data_h p2p_data, void *user_data)
+{
+ g_print("P2P data is received\n");
+
+ print_received_data(p2p_data);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_p2p_send(gpointer data,
+ gpointer user_data)
+{
+
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+ net_nfc_exchanger_data_h exch_data = NULL;
+ data_h rawdata = NULL;
+
+ net_nfc_create_ndef_message (&msg);
+ net_nfc_create_uri_type_record (&record ,"http://www.samsung.com" ,NET_NFC_SCHEMA_FULL_URI);
+ net_nfc_append_record_to_ndef_message (msg ,record);
+ net_nfc_create_rawdata_from_ndef_message(msg, &rawdata);
+
+ if((result = net_nfc_client_create_exchanger_data(&exch_data, rawdata)) != NET_NFC_OK)
+ {
+ net_nfc_free_data(rawdata);
+
+ g_printerr("create exchanger data is failed\n");
+ return;
+ }
+ net_nfc_free_data(rawdata);
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(global_handle));
+
+ net_nfc_client_p2p_send(
+ exch_data,
+ global_handle,
+ p2p_send,
+ user_data);
+}
+
+void net_nfc_test_p2p_send_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+ net_nfc_exchanger_data_h exch_data = NULL;
+ data_h rawdata = NULL;
+
+ net_nfc_create_ndef_message (&msg);
+ net_nfc_create_uri_type_record (&record ,"http://www.samsung.com", NET_NFC_SCHEMA_FULL_URI);
+ net_nfc_append_record_to_ndef_message (msg, record);
+ net_nfc_create_rawdata_from_ndef_message(msg, &rawdata);
+ net_nfc_client_create_exchanger_data(&exch_data, rawdata);
+
+ result = net_nfc_client_p2p_send_sync(exch_data, global_handle);
+
+ g_print(" P2P send sync result: %d\n", result);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_p2p_set_device_discovered(gpointer data,
+ gpointer user_data)
+{
+ g_print("Waiting for Device Discovered Singal\n");
+
+ net_nfc_client_p2p_set_device_discovered(p2p_device_discovered, user_data);
+
+ g_print("Device Discovered set\n");
+}
+
+void net_nfc_test_p2p_set_device_detached(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_p2p_set_device_detached(p2p_device_detached,
+ user_data);
+}
+
+void net_nfc_test_p2p_set_data_received(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_p2p_set_data_received(p2p_device_data_received,
+ user_data);
+}
+
+net_nfc_target_handle_h net_nfc_test_device_get_target_handle(void)
+{
+ return global_handle;
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <glib-object.h>
+
+#include "net_nfc_target_info.h"
+#include "net_nfc_data.h"
+#include "net_nfc_client_se.h"
+#include "net_nfc_test_se.h"
+#include "net_nfc_typedef.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_test_util.h"
+
+
+static void run_next_callback(gpointer user_data);
+
+static void send_apdu_cb(net_nfc_error_e result, data_h data, void *user_data);
+
+static void set_secure_element_cb(net_nfc_error_e result, void *user_data);
+
+static void open_secure_element_cb(net_nfc_error_e result,
+ net_nfc_target_handle_h handle, void *user_data);
+
+static void close_secure_element_cb(net_nfc_error_e result, void *user_data);
+
+static void get_atr_secure_element_cb(net_nfc_error_e result, data_h data,
+ void *user_data);
+
+static void se_set_event_cb(net_nfc_message_e event, void *user_data);
+
+static void se_ese_detection_cb(net_nfc_target_handle_h handle,
+ int dev_type, data_h data, void *user_data);
+
+static void se_set_transaction_cb(data_h aid,
+ data_h param,
+ void *user_data);
+
+/*This handle would be intialized by open secure element callback function*/
+static net_nfc_target_handle_h global_handle = NULL;
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+static void send_apdu_cb(net_nfc_error_e result, data_h data, void *user_data)
+{
+ g_print(" Send apdu data completed \n");
+ print_received_data(data);
+ run_next_callback(user_data);
+}
+
+static void set_secure_element_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("Set Secure Element completed : %d\n", result);
+ run_next_callback(user_data);
+}
+
+static void open_secure_element_cb(net_nfc_error_e result,
+ net_nfc_target_handle_h handle, void* user_data)
+{
+ g_print("Open secure element completed\n");
+ // assigning received handle
+ global_handle = handle;
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+ run_next_callback(user_data);
+}
+
+static void close_secure_element_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("close secure element completed %d\n", result);
+ run_next_callback(user_data);
+}
+
+static void get_atr_secure_element_cb(net_nfc_error_e result, data_h data,
+ void* user_data)
+{
+ g_print("get atr completed\n");
+ print_received_data(data);
+ run_next_callback(user_data);
+}
+
+static void se_set_event_cb(net_nfc_message_e event, void* user_data)
+{
+ g_print("Event callback set successfully\n");
+ g_print(" Event received %d", event);
+ run_next_callback(user_data);
+}
+
+static void se_ese_detection_cb(net_nfc_target_handle_h handle,
+ int dev_type,
+ data_h data,
+ void *user_data)
+{
+ g_print("Set ese detection callback successfully\n");
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+ g_print(" dev type %d\n", dev_type);
+ print_received_data(data);
+}
+
+static void se_set_transaction_cb(data_h aid,
+ data_h param,
+ void *user_data)
+{
+ g_print("Set transaction callback successfully\n");
+ g_print("*****displaying Aid data****\n");
+ print_received_data(aid);
+ g_print("*****displaying param data ****\n");
+ print_received_data(param);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_se_send_apdu(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_h apdu_data = NULL;
+ uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C};
+
+ net_nfc_create_data(&apdu_data, apdu_cmd, 4);
+
+ result = net_nfc_client_se_send_apdu(global_handle,
+ apdu_data,
+ send_apdu_cb,
+ user_data);
+}
+
+void net_nfc_test_se_send_apdu_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_h apdu_data = NULL;
+ uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C};
+ data_h response = NULL;
+
+ net_nfc_create_data(&apdu_data, apdu_cmd, 4);
+ result = net_nfc_client_se_send_apdu_sync(global_handle,
+ apdu_data,
+ &response);
+
+ g_print(" Send apdu data sync completed %d\n", result);
+ print_received_data(response);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_se_set_secure_element_type(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_UICC;
+
+ result = net_nfc_client_se_set_secure_element_type(
+ se_type,
+ set_secure_element_cb,
+ user_data);
+}
+
+void net_nfc_test_se_set_secure_element_type_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_UICC;
+
+ result = net_nfc_client_se_set_secure_element_type_sync(se_type);
+ g_print(" Set Secure element type completed %d\n", result);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_se_open_internal_secure_element(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_UICC;
+
+ result = net_nfc_client_se_open_internal_secure_element(
+ se_type,
+ open_secure_element_cb,
+ user_data);
+
+}
+
+void net_nfc_test_se_open_internal_secure_element_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_UICC;
+
+ result = net_nfc_client_se_open_internal_secure_element_sync(
+ se_type,
+ &global_handle);
+
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(global_handle));
+ g_print(" open secure element completed %d\n", result);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_se_close_internal_secure_element(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ result = net_nfc_client_se_close_internal_secure_element(
+ global_handle,
+ close_secure_element_cb,
+ user_data);
+
+}
+
+void net_nfc_test_se_close_internal_secure_element_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+ result = net_nfc_client_se_close_internal_secure_element_sync(global_handle);
+ g_print("close secure element completed %d\n", result);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_se_get_atr(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+
+
+ result = net_nfc_client_se_get_atr(
+ global_handle,
+ get_atr_secure_element_cb,
+ user_data);
+
+}
+
+void net_nfc_test_se_get_atr_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_h attr_data = NULL;
+
+ result = net_nfc_client_se_get_atr_sync(
+ global_handle,
+ &attr_data);
+
+ g_print("Get atr data sync completed %d\n", result);
+ print_received_data(attr_data);
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_se_set_event_cb(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_se_set_event_cb(se_set_event_cb,
+ user_data);
+}
+
+void net_nfc_test_se_unset_event_cb(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_se_unset_event_cb();
+ g_print(" Event unset callback successfully\n");
+}
+
+void net_nfc_test_se_set_ese_detection_cb(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_se_set_ese_detection_cb(se_ese_detection_cb,
+ user_data);
+}
+
+void net_nfc_test_se_unset_ese_detection_cb(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_se_unset_ese_detection_cb();
+ g_print("Detection unset callback successfuly\n");
+}
+
+void net_nfc_test_se_set_transaction_event_cb(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_se_set_transaction_event_cb(se_set_transaction_cb,
+ user_data);
+}
+
+void net_nfc_test_se_unset_transaction_event_cb(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_se_unset_transaction_event_cb();
+ g_print("Transaction unset callback successfully\n");
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib-object.h>
+#include"net_nfc_test_snep.h"
+#include"net_nfc_typedef.h"
+#include"net_nfc_target_info.h"
+#include"net_nfc_client_snep.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_ndef_message.h"
+#include "net_nfc_client_tag.h"
+#include "net_nfc_ndef_record.h"
+
+static net_nfc_target_info_h target_info = NULL;
+static net_nfc_snep_handle_h snep_handle = NULL;
+
+static void run_next_callback(gpointer user_data);
+
+static void snep_tag_discovered_cb(net_nfc_target_info_h info,
+ void *user_data);
+
+static void snep_tag_detached_cb(void *user_data);
+
+static void snep_start_server_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
+
+static void snep_start_client_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
+
+static void snep_send_request_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
+
+
+static void snep_register_server_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data);
+
+/******************************Callbacks*********************************************/
+
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+static void snep_tag_detached_cb(void *user_data)
+{
+ g_print("TagDetached\n");
+}
+
+static void snep_tag_discovered_cb(net_nfc_target_info_h info,
+ void *user_data)
+{
+ g_print("TagDiscovered\n");
+
+ net_nfc_duplicate_target_info(info, &target_info);
+ run_next_callback(user_data);
+}
+
+static void snep_start_server_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
+{
+
+ snep_handle = target;
+
+ g_print("snep_start_server_cb Completed %d\n", event);
+ g_print("snep_start_server_cb Completed %d\n", result);
+
+ net_nfc_util_print_ndef_message (msg);
+
+ run_next_callback(user_data);
+
+}
+
+static void snep_start_client_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
+{
+
+ g_print("snep_start_client_cb Completed %d\n", event);
+ g_print("snep_send_request_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+
+static void snep_send_request_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
+{
+
+ g_print("snep_send_request_cb Completed %d\n", event);
+ g_print("snep_start_server_cb Completed %d\n", result);
+
+ net_nfc_util_print_ndef_message (msg);
+
+ run_next_callback(user_data);
+}
+
+
+static void snep_register_server_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
+ {
+
+ g_print("snep_register_server_cb Completed %d\n", event);
+ g_print("snep_register_server_cb Completed %d\n", result);
+
+ net_nfc_util_print_ndef_message (msg);
+
+ run_next_callback(user_data);
+ }
+
+/*
+static void snep_unregister_server_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
+ {
+
+ g_print("snep_register_server_cb Completed %d\n", event);
+ g_print("snep_register_server_cb Completed %d\n", result);
+
+ net_nfc_util_print_ndef_message (msg);
+
+ run_next_callback(user_data);
+ }
+*/
+
+/******************************API Calls*********************************************/
+
+void net_nfc_test_snep_set_tag_discovered(gpointer data,
+ gpointer user_data)
+{
+ g_print("Waiting for TagDiscovered Singal\n");
+
+ net_nfc_client_tag_unset_tag_detached();
+ net_nfc_client_tag_set_tag_detached(snep_tag_detached_cb, NULL);
+
+ net_nfc_client_tag_unset_tag_discovered();
+ net_nfc_client_tag_set_tag_discovered(snep_tag_discovered_cb, user_data);
+}
+
+
+void net_nfc_test_snep_start_server(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_client_snep_start_server(target_info->handle,
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16,
+ snep_start_server_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_start_server failed: %d\n", result);
+ return;
+ }
+
+}
+
+
+void net_nfc_test_snep_start_server_sync(gpointer data,
+ gpointer user_data)
+{
+ /*
+
+ net_nfc_error_e result;
+ guint out_result;
+ ndef_message_h msg=NULL;
+
+ result = net_nfc_client_snep_start_server_sync(target_info->handle,
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16,
+ &out_result,
+ msg);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_start_server failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ net_nfc_util_print_ndef_message (msg);
+ run_next_callback(user_data);
+*/
+
+}
+
+
+void net_nfc_test_snep_start_client(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ result = net_nfc_client_snep_start_client(target_info->handle,
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16,
+ snep_start_client_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_start_client failed: %d\n", result);
+ return;
+ }
+}
+
+
+void net_nfc_test_snep_start_client_sync(gpointer data,
+ gpointer user_data)
+{
+ /*
+
+ net_nfc_error_e result;
+ guint out_result;
+
+ result = net_nfc_client_snep_start_client_sync(target_info->handle,
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16,
+ &out_result);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_start_client_sync failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_snep_start_client_sync out_result: %d\n", out_result);
+ run_next_callback(user_data);
+*/
+
+}
+
+void net_nfc_test_snep_send_client_request(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result= NET_NFC_OK;
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+
+ if( (error = net_nfc_create_uri_type_record(&record,
+ "http://www.naver.com",
+ NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_append_record_to_ndef_message(
+ msg,
+ record)) == NET_NFC_OK)
+ {
+ result = net_nfc_client_snep_send_client_request(
+ target_info->handle,
+ NET_NFC_SNEP_GET,
+ msg,
+ snep_send_request_cb,
+ user_data);
+ }
+ }
+ }
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_send_client_request failed: %d\n", result);
+ return;
+ }
+
+}
+
+
+void net_nfc_test_snep_send_client_request_sync(gpointer data,
+ gpointer user_data)
+{
+ /*
+
+ net_nfc_error_e result= NET_NFC_OK;
+ net_nfc_error_e error = NET_NFC_OK;
+ ndef_message_h msg = NULL;
+ ndef_record_h record = NULL;
+ ndef_message_h out_msg = NULL;
+ guint out_result;
+
+ if( (error = net_nfc_create_uri_type_record(&record,
+ "http://www.naver.com",
+ NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
+ {
+ if( (error = net_nfc_append_record_to_ndef_message(
+ msg,
+ record)) == NET_NFC_OK)
+ {
+ result = net_nfc_client_snep_send_client_request_sync(
+ target_info->handle,
+ NET_NFC_SNEP_GET,
+ msg,
+ &out_result,
+ out_msg);
+ }
+ }
+ }
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_send_client_request_sync failed: %d\n", result);
+ run_next_callback(user_data);
+ return;
+ }
+
+ g_print(" net_nfc_test_snep_send_client_request_sync out_result: %d\n", out_result);
+
+ net_nfc_util_print_ndef_message (msg);
+ run_next_callback(user_data);
+*/
+
+}
+
+
+void net_nfc_test_snep_register_server(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result= NET_NFC_OK;
+
+ result = net_nfc_client_snep_register_server(
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16,
+ snep_register_server_cb,
+ user_data);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_register_server failed: %d\n", result);
+ return;
+ }
+}
+
+void net_nfc_test_snep_unregister_server(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result= NET_NFC_OK;
+
+ result = net_nfc_client_snep_unregister_server(
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_register_server failed: %d\n", result);
+ return;
+ }
+}
+
+
+void net_nfc_test_snep_stop_service(gpointer data,
+ gpointer user_data)
+{
+/*
+ net_nfc_error_e result= NET_NFC_OK;
+
+ result = net_nfc_client_snep_register_server(
+ "urn:nfc:xsn:samsung.com:testllcp",
+ 16);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_register_server failed: %d\n", result);
+ return;
+ }
+*/
+}
+
+
+void net_nfc_test_snep_stop_service_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result= NET_NFC_OK;
+
+ result = net_nfc_client_snep_stop_service_sync(
+ target_info->handle,
+ snep_handle);
+
+ if(result != NET_NFC_OK)
+ {
+ g_print(" net_nfc_test_snep_register_server failed: %d\n", result);
+ return;
+ }
+}
+
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib-object.h>
+
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_client_tag.h"
+#include "net_nfc_test_tag.h"
+
+static void run_next_callback(gpointer user_data);
+
+static gchar *tag_type_to_string(net_nfc_target_type_e dev_type);
+
+static void print_is_tag_connected(net_nfc_target_type_e dev_type);
+
+static void print_get_current_tag_info(net_nfc_target_info_h info);
+
+static void print_get_current_target_handle(net_nfc_target_handle_h handle);
+
+static void is_tag_connected_completed(net_nfc_error_e result,
+ net_nfc_target_type_e dev_type,
+ void *user_data);
+
+static void get_current_tag_info_completed(net_nfc_error_e result,
+ net_nfc_target_info_h info,
+ void *user_data);
+
+static void get_current_target_handle_completed(net_nfc_error_e result,
+ net_nfc_target_handle_h handle,
+ void *user_data);
+
+static void tag_detached(void *user_data);
+
+static void tag_discovered(net_nfc_target_info_h info,
+ void *user_data);
+
+static net_nfc_target_info_h global_info = NULL;
+
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+
+ callback();
+ }
+}
+
+static gchar *tag_type_to_string(net_nfc_target_type_e dev_type)
+{
+ switch(dev_type)
+ {
+ case NET_NFC_UNKNOWN_TARGET:
+ return "Unknown Target";
+ case NET_NFC_GENERIC_PICC:
+ return "Generic PICC";
+ case NET_NFC_ISO14443_A_PICC:
+ return "ISO14443 PICC";
+ case NET_NFC_ISO14443_4A_PICC:
+ return "ISO14443 4A PICC";
+ case NET_NFC_ISO14443_3A_PICC:
+ return "ISO14443 3A PICC";
+ case NET_NFC_MIFARE_MINI_PICC:
+ return "Mifare mini PICC";
+ case NET_NFC_MIFARE_1K_PICC:
+ return "Mifare 1K PICC";
+ case NET_NFC_MIFARE_4K_PICC:
+ return "Mifare 4K PICC";
+ case NET_NFC_MIFARE_ULTRA_PICC:
+ return "Mifare Ultra PICC";
+ case NET_NFC_MIFARE_DESFIRE_PICC:
+ return "Mifare Desfire PICC";
+ case NET_NFC_ISO14443_B_PICC:
+ return "ISO14443 B PICC";
+ case NET_NFC_ISO14443_4B_PICC:
+ return "ISO14443 4B PICC";
+ case NET_NFC_ISO14443_BPRIME_PICC:
+ return "ISO14443 BPRIME PICC";
+ case NET_NFC_FELICA_PICC:
+ return "Felica PICC";
+ case NET_NFC_JEWEL_PICC:
+ return "Jewel PICC";
+ case NET_NFC_ISO15693_PICC:
+ return "ISO15693 PICC";
+ case NET_NFC_NFCIP1_TARGET:
+ return "NFCIP1 Target";
+ case NET_NFC_NFCIP1_INITIATOR:
+ return "NFCIP1 Initiator";
+ default:
+ break;
+ }
+ return "Invalid Target";
+}
+
+static void print_is_tag_connected(net_nfc_target_type_e dev_type)
+{
+ if (global_info)
+ {
+ net_nfc_target_type_e type;
+
+ net_nfc_get_tag_type(global_info, &type);
+
+ if(dev_type == type)
+ g_print("DevType is same as Discovered tag\n");
+ }
+}
+
+static void print_get_current_tag_info(net_nfc_target_info_h info)
+{
+ net_nfc_target_handle_h handle;
+
+ if (global_info == NULL)
+ {
+ g_print("Discovered tag info does not exist\n");
+ return;
+ }
+
+ if (info == NULL)
+ {
+ g_print("Current tag info does not exist\n");
+ return;
+ }
+
+ net_nfc_get_tag_handle(info, &handle);
+ print_get_current_target_handle(handle);
+
+ return;
+}
+
+static void print_get_current_target_handle(net_nfc_target_handle_h handle)
+{
+ net_nfc_target_handle_h global_handle;
+ guint global_handle_id;
+ guint handle_id;
+
+ net_nfc_get_tag_handle(global_info, &global_handle);
+
+ global_handle_id = GPOINTER_TO_UINT(global_handle);
+ handle_id = GPOINTER_TO_UINT(handle);
+
+ g_print("Tag handle %x, Current Tag handle %x\n",
+ global_handle_id,
+ handle_id);
+ if (global_handle_id == handle_id)
+ g_print("Current Tag is matched discovered Tag\n");
+}
+
+static void tag_detached(void *user_data)
+{
+ g_print("TagDetached\n");
+}
+
+static void is_tag_connected_completed(net_nfc_error_e result,
+ net_nfc_target_type_e dev_type,
+ void *user_data)
+{
+ g_print("IsTagConnected Completed %d\n", result);
+ g_print("--- dev type : %s (%d)\n", tag_type_to_string(dev_type),
+ dev_type);
+
+ if (result == NET_NFC_OK)
+ print_is_tag_connected(dev_type);
+ else if (result == NET_NFC_NOT_CONNECTED)
+ g_print("NET_NFC_NOT_CONNECTED\n");
+
+ run_next_callback(user_data);
+}
+
+static void get_current_tag_info_completed(net_nfc_error_e result,
+ net_nfc_target_info_h info,
+ void *user_data)
+{
+ g_print("GetCurrentTagInfo Completed %d\n", result);
+
+ if (result == NET_NFC_OK)
+ print_get_current_tag_info(info);
+
+ run_next_callback(user_data);
+}
+
+static void get_current_target_handle_completed(net_nfc_error_e result,
+ net_nfc_target_handle_h handle,
+ void *user_data)
+{
+ g_print("GetCurrentTargetHandle Completed %d\n", result);
+
+ if (result == NET_NFC_OK)
+ print_get_current_target_handle(handle);
+
+ run_next_callback(user_data);
+}
+
+
+static void tag_discovered(net_nfc_target_info_h info,
+ void *user_data)
+{
+ g_print("TagDiscovered\n");
+
+ net_nfc_duplicate_target_info(info, &global_info);
+
+ run_next_callback(user_data);
+}
+
+
+
+void net_nfc_test_tag_is_tag_connected(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_tag_is_tag_connected(is_tag_connected_completed,
+ user_data);
+}
+
+void net_nfc_test_tag_get_current_tag_info(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_tag_get_current_tag_info(get_current_tag_info_completed,
+ user_data);
+}
+
+void net_nfc_test_tag_get_current_target_handle(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_tag_get_current_target_handle(
+ get_current_target_handle_completed,
+ user_data);
+}
+
+void net_nfc_test_tag_is_tag_connected_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ net_nfc_target_type_e dev_type;
+
+ result = net_nfc_client_tag_is_tag_connected_sync(&dev_type);
+
+ if (result == NET_NFC_OK)
+ print_is_tag_connected(dev_type);
+ else if (result == NET_NFC_NOT_CONNECTED)
+ g_print("NET_NFC_NOT_CONNECTED\n");
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_tag_get_current_tag_info_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ net_nfc_target_info_h info;
+
+ result = net_nfc_client_tag_get_current_tag_info_sync(&info);
+
+ if (result == NET_NFC_OK)
+ print_get_current_tag_info(info);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_tag_get_current_target_handle_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ net_nfc_target_handle_h handle;
+
+ result = net_nfc_client_tag_get_current_target_handle_sync(&handle);
+
+ if (result == NET_NFC_OK)
+ print_get_current_target_handle(handle);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_tag_set_tag_discovered(gpointer data,
+ gpointer user_data)
+{
+ g_print("Waiting for TagDiscovered Signal\n");
+
+ net_nfc_client_tag_unset_tag_detached();
+
+ net_nfc_client_tag_set_tag_detached(tag_detached, NULL);
+
+ net_nfc_client_tag_unset_tag_discovered();
+
+ net_nfc_client_tag_set_tag_discovered(tag_discovered, user_data);
+}
+
+net_nfc_target_info_h net_nfc_test_tag_get_target_info(void)
+{
+ return global_info;
+}
+
+void net_nfc_test_tag_set_tag_detached(gpointer data,
+ gpointer user_data)
+{
+ g_print("Waiting for TagDetached Singal\n");
+
+ net_nfc_client_tag_set_tag_detached(tag_detached, NULL);
+}
+
+void net_nfc_test_tag_set_filter(gpointer data, gpointer user_data)
+{
+ net_nfc_event_filter_e filter = NET_NFC_ALL_ENABLE;
+
+ net_nfc_client_tag_set_filter(filter);
+}
+
+void net_nfc_test_tag_get_filter(gpointer data, gpointer user_data)
+{
+ net_nfc_event_filter_e filter = NET_NFC_ALL_DISABLE;
+
+ filter = net_nfc_client_tag_get_filter();
+
+ g_print(" NFC tag filter = %d", filter);
+}
--- /dev/null
+/*
+* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "net_nfc_test_tag_felica.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_test_tag.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_test_util.h"
+#include "net_nfc_client_tag_felica.h"
+
+
+static net_nfc_target_handle_h get_handle();
+
+static void run_next_callback(gpointer user_data);
+
+static void felica_cb(net_nfc_error_e result,
+ data_h resp_data,
+ void *user_data);
+
+
+static net_nfc_target_handle_h get_handle()
+{
+ net_nfc_target_info_h info = NULL;
+ net_nfc_target_handle_h handle = NULL;
+
+ info = net_nfc_test_tag_get_target_info();
+
+ net_nfc_get_tag_handle(info, &handle);
+
+ return handle;
+}
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+
+ callback();
+ }
+}
+
+static void felica_cb(net_nfc_error_e result,
+ data_h resp_data,
+ void *user_data)
+{
+ g_print("felica_cb Completed %d\n", result);
+
+ print_received_data(resp_data);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_felica_poll(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ net_nfc_felica_poll_request_code_e req_code = 0x00;
+ uint8_t time_slot = 2;
+
+ handle = get_handle();
+ if (handle == NULL)
+ return ;
+
+ result = net_nfc_client_felica_poll(handle,
+ req_code,
+ time_slot,
+ felica_cb,
+ user_data);
+}
+
+void net_nfc_test_felica_request_service(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t number_of_area_service = 4;
+ uint16_t area_service_list[10] = { 0,};
+ uint8_t number_of_services = 5;
+
+ handle = get_handle();
+ if (handle == NULL)
+ return ;
+
+ result = net_nfc_client_felica_request_service(handle,
+ number_of_area_service,
+ area_service_list,
+ number_of_services,
+ felica_cb,
+ user_data);
+}
+
+void net_nfc_test_felica_request_response(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+
+ handle = get_handle();
+ if (handle == NULL)
+ return ;
+
+ result = net_nfc_client_felica_request_response(handle,
+ felica_cb,
+ user_data);
+}
+
+void net_nfc_test_felica_read_without_encryption(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t number_of_services = 10;
+ uint16_t service_list[2] = {0,};
+ uint8_t number_of_blocks = 1;
+ uint8_t block_list[3] = {0,};
+
+ handle = get_handle();
+ if (handle == NULL)
+ return ;
+
+ result = net_nfc_client_felica_read_without_encryption(handle,
+ number_of_services,
+ service_list,
+ number_of_blocks,
+ block_list,
+ felica_cb,
+ user_data);
+}
+
+void net_nfc_test_felica_write_without_encryption(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t number_of_services = 10;
+ uint16_t service_list[2] = {0,};
+ uint8_t number_of_blocks = 1;
+ uint8_t block_list[3] = {0,};
+ data_h data_to_write = NULL;
+
+ handle = get_handle();
+ if (handle == NULL)
+ return ;
+
+ result = net_nfc_client_felica_write_without_encryption(handle,
+ number_of_services,
+ service_list,
+ number_of_blocks,
+ block_list,
+ data_to_write,
+ felica_cb,
+ user_data);
+}
+
+void net_nfc_test_felica_request_system_code(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+
+ handle = get_handle();
+ if (handle == NULL)
+ return ;
+
+ result = net_nfc_client_felica_request_system_code(handle,
+ felica_cb,
+ user_data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "net_nfc_tag_mifare.h"
+#include "net_nfc_test_tag_mifare.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_test_tag.h"
+#include "net_nfc_test_util.h"
+
+
+static net_nfc_target_handle_h tag_get_handle(void);
+
+static void mifare_read_cb(net_nfc_error_e result,
+ data_h resp_data,
+ void *user_data);
+
+static void mifare_write_block_cb(net_nfc_error_e result, void* user_data);
+
+static void mifare_write_page_cb(net_nfc_error_e result, void* user_data);
+
+static void mifare_write_mifare_incr_cb(net_nfc_error_e result, void* user_data);
+
+static void mifare_write_mifare_decr_cb(net_nfc_error_e result, void* user_data);
+
+static void mifare_write_mifare_transfer_cb(net_nfc_error_e result, void* user_data);
+
+static void mifare_write_mifare_restore_cb(net_nfc_error_e result, void* user_data);
+
+static void mifare_write_auth_keyA_cb(net_nfc_error_e result, void* user_data);
+
+static void mifare_write_auth_keyB_cb(net_nfc_error_e result, void* user_data);
+
+
+static net_nfc_target_handle_h tag_get_handle(void)
+{
+ net_nfc_target_info_h info = NULL;
+ net_nfc_target_handle_h handle = NULL;
+
+ info = net_nfc_test_tag_get_target_info();
+
+ net_nfc_get_tag_handle(info, &handle);
+
+ return handle;
+}
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+static void mifare_read_cb(net_nfc_error_e result,
+ data_h resp_data,
+ void *user_data)
+{
+ g_print("mifare_read_cb Completed %d\n", result);
+ print_received_data(resp_data);
+
+ run_next_callback(user_data);
+}
+
+static void mifare_write_block_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("mifare_write_block_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void mifare_write_page_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("mifare_write_page_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void mifare_write_mifare_incr_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("mifare_write_mifare_incr_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void mifare_write_mifare_decr_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("mifare_write_mifare_decr_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void mifare_write_mifare_transfer_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("mifare_write_mifare_transfer_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void mifare_write_mifare_restore_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("mifare_write_mifare_restore_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void mifare_write_auth_keyA_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("mifare_write_auth_keyA_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void mifare_write_auth_keyB_cb(net_nfc_error_e result, void* user_data)
+{
+ g_print("mifare_write_auth_keyB_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+
+void net_nfc_test_tag_mifare_read(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t block_index = 0x0;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ result = net_nfc_client_mifare_read(handle,
+ block_index,
+ mifare_read_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_mifare_write_block(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ data_h write_data = NULL;
+ // create 4 bytes data mifare page size is 4 bytes
+ uint8_t buffer_data [17] = "aaaabbbbccccdddd";
+
+ net_nfc_create_data(&write_data, buffer_data, 16);
+
+ uint8_t block_index = 0x04;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ result = net_nfc_client_mifare_write_block(handle,
+ block_index,
+ (data_h)& write_data,
+ mifare_write_block_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_mifare_write_page(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ data_h write_data = NULL;
+ // create 4 bytes data mifare page size is 4 bytes
+ uint8_t buffer_data [5] = "aaaa";
+
+ net_nfc_create_data(&write_data, buffer_data, 4);
+
+ uint8_t block_index = 0x04;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ result = net_nfc_client_mifare_write_page(handle,
+ block_index,
+ (data_h)& write_data,
+ mifare_write_page_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_mifare_increment(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ int value = 1;
+ uint8_t block_index = 0x05;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+ result = net_nfc_client_mifare_increment(handle,
+ block_index,
+ value,
+ mifare_write_mifare_incr_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_mifare_decrement(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ int value = 1;
+ uint8_t block_index = 0x05;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+ result = net_nfc_client_mifare_decrement(handle,
+ block_index,
+ value,
+ mifare_write_mifare_decr_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_mifare_transfer(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t block_index = 0x08;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+ result = net_nfc_client_mifare_transfer(handle,
+ block_index,
+ mifare_write_mifare_transfer_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_mifare_restore(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ uint8_t block_index = 0x08;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ result = net_nfc_client_mifare_restore(handle,
+ block_index,
+ mifare_write_mifare_restore_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_mifare_authenticate_with_keyA(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ data_h auth_key = NULL;
+ uint8_t sector_index = 0x02;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ result = net_nfc_client_mifare_create_default_key(&auth_key);
+ g_print("default key create %d", result);
+
+ result = net_nfc_client_mifare_authenticate_with_keyA(
+ handle,
+ sector_index,
+ auth_key,
+ mifare_write_auth_keyA_cb,
+ user_data);
+}
+
+void net_nfc_test_tag_mifare_authenticate_with_keyB(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_target_handle_h handle = NULL;
+ data_h auth_key = NULL;
+ uint8_t sector_index = 0x02;
+
+ handle = tag_get_handle();
+ if (handle == NULL)
+ {
+ g_printerr("Handle is NULL\n");
+
+ run_next_callback(user_data);
+ return;
+ }
+ g_print("Handle is %#x\n", GPOINTER_TO_UINT(handle));
+
+ result = net_nfc_client_mifare_create_default_key(&auth_key);
+ g_print("default key create %d", result);
+
+ result = net_nfc_client_mifare_authenticate_with_keyB(
+ handle,
+ sector_index,
+ auth_key,
+ mifare_write_auth_keyB_cb,
+ user_data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib-object.h>
+
+#include "net_nfc_client_test.h"
+
+
+
+static void run_next_callback(gpointer user_data);
+
+static void sim_test_completed(net_nfc_error_e result,
+ void *user_data);
+
+static void prbs_test_completed(net_nfc_error_e result,
+ void *user_data);
+
+static void get_firmware_version_completed(net_nfc_error_e result,
+ char *version,
+ void *user_data);
+
+static void set_ee_data_completed(net_nfc_error_e reuslt,
+ void *user_data);
+
+
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+
+
+static void sim_test_completed(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print("SimTestCompleted Completed %d\n", result);
+ run_next_callback(user_data);
+}
+
+
+
+static void prbs_test_completed(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print("PrbsTest Completed %d\n", result);
+ run_next_callback(user_data);
+}
+
+
+
+static void get_firmware_version_completed(net_nfc_error_e result,
+ char *version,
+ void *user_data)
+{
+ g_print("GetFirmwareVersion Completed %d: %s\n", result, version);
+ run_next_callback(user_data);
+}
+
+
+
+static void set_ee_data_completed(net_nfc_error_e result,
+ void *user_data)
+{
+ g_print("SetEeData Completed %d\n", result);
+ run_next_callback(user_data);
+}
+
+
+void net_nfc_test_test_sim_test(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_test_sim_test(sim_test_completed, user_data);
+}
+
+
+
+void net_nfc_test_test_prbs_test(gpointer data,
+ gpointer user_data)
+{
+ /* FIXME : fill right value */
+ uint32_t tech = 0;
+ uint32_t rate = 0;
+
+ net_nfc_client_test_prbs_test(tech,
+ rate,
+ prbs_test_completed,
+ user_data);
+}
+
+
+
+void net_nfc_test_test_get_firmware_version(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_client_test_get_firmware_version(
+ get_firmware_version_completed,
+ user_data);
+}
+
+
+
+void net_nfc_test_test_set_ee_data(gpointer data,
+ gpointer user_data)
+{
+
+ /* FIXME : fill right value */
+ int mode = 0;
+ int reg_id = 0;
+ data_h ee_data = (data_h)data;
+
+ net_nfc_client_test_set_ee_data(mode,
+ reg_id,
+ ee_data,
+ set_ee_data_completed,
+ user_data);
+
+}
+
+
+
+void net_nfc_test_test_sim_test_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ result = net_nfc_client_test_sim_test_sync();
+ g_print("SimTest: %d\n", result);
+ run_next_callback(user_data);
+}
+
+
+
+void net_nfc_test_test_prbs_test_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+
+ /* FIXME : fill right value */
+ uint32_t tech = 0;
+ uint32_t rate = 0;
+ result = net_nfc_client_test_prbs_test_sync(tech, rate);
+ g_print("PrbsTest: %d\n", result);
+ run_next_callback(user_data);
+
+}
+
+
+
+void net_nfc_test_test_get_firmware_version_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result;
+ char *version = NULL;
+
+ result = net_nfc_client_test_get_firmware_version_sync(&version);
+
+ g_print("GetFirmwareVersion: %d, %s\n", result, version);
+ run_next_callback(user_data);
+
+}
+
+
+
+void net_nfc_test_test_set_ee_data_sync(gpointer data,
+ gpointer user_data)
+{
+
+ net_nfc_error_e result;
+
+ /* FIXME : fill right value */
+ int mode = 0;
+ int reg_id = 0;
+ data_h ee_data = (data_h)data;
+
+ result = net_nfc_client_test_set_ee_data_sync(mode,
+ reg_id,
+ ee_data);
+ g_print("SetEeData: %d\n", result);
+ run_next_callback(user_data);
+
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "net_nfc_client_transceive.h"
+#include "net_nfc_test_transceive.h"
+#include "net_nfc_test_util.h"
+#include "net_nfc_target_info.h"
+#include "net_nfc_typedef_internal.h"
+#include "net_nfc_test_tag.h"
+
+
+static void call_transceive_data_cb(net_nfc_error_e result,
+ data_h resp_data,
+ void *user_data);
+
+static void call_transceive_cb(net_nfc_error_e result,
+ void* user_data);
+
+static void run_next_callback(gpointer user_data);
+
+
+static void run_next_callback(gpointer user_data)
+{
+ if (user_data)
+ {
+ GCallback callback;
+
+ callback = (GCallback)(user_data);
+ callback();
+ }
+}
+
+
+static void call_transceive_cb(net_nfc_error_e result,
+ void* user_data)
+{
+ g_print("call_transceive_cb Completed %d\n", result);
+
+ run_next_callback(user_data);
+}
+
+static void call_transceive_data_cb(net_nfc_error_e result,
+ data_h resp_data,
+ void *user_data)
+{
+ g_print("call_transceive_data_cb Completed %d\n", result);
+ print_received_data(resp_data);
+
+ run_next_callback(user_data);
+}
+
+void net_nfc_test_transceive(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_s raw_data = {NULL,};
+ net_nfc_target_info_h info = NULL;
+ net_nfc_target_handle_h handle = NULL;
+
+ info = net_nfc_test_tag_get_target_info();
+
+ net_nfc_get_tag_handle(info, &handle);
+
+ result =net_nfc_client_transceive(handle,
+ (data_h)&raw_data,
+ call_transceive_cb,
+ user_data);
+}
+
+void net_nfc_test_transceive_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_s raw_data = {NULL,};
+ net_nfc_target_info_h info = NULL;
+ net_nfc_target_handle_h handle = NULL;
+
+ info = net_nfc_test_tag_get_target_info();
+
+ net_nfc_get_tag_handle(info, &handle);
+
+ result = net_nfc_client_transceive_sync(handle, (data_h)& raw_data);
+
+ g_print("Transceive Sync is completed \n");
+}
+
+void net_nfc_test_transceive_data(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_s raw_data = {NULL,};
+ net_nfc_target_info_h info = NULL;
+ net_nfc_target_handle_h handle = NULL;
+
+ info = net_nfc_test_tag_get_target_info();
+
+ net_nfc_get_tag_handle(info, &handle);
+
+ result = net_nfc_client_transceive_data(handle,
+ (data_h) &raw_data,
+ call_transceive_data_cb,
+ user_data);
+}
+
+void net_nfc_test_transceive_data_sync(gpointer data,
+ gpointer user_data)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ data_s raw_data = {NULL};
+ data_h response = NULL;
+ net_nfc_target_info_h info = NULL;
+ net_nfc_target_handle_h handle = NULL;
+
+ info = net_nfc_test_tag_get_target_info();
+
+ net_nfc_get_tag_handle(info, &handle);
+
+ result = net_nfc_client_transceive_data_sync(handle,
+ &raw_data,
+ &response);
+ print_received_data(response);
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "net_nfc_test_util.h"
+
+
+void print_received_data(data_h data)
+{
+ guint8 *buffer = NULL;
+ gint i;
+ gint len = 0;
+
+ buffer = (guint8 *)net_nfc_get_data_buffer(data);
+ if (buffer == NULL)
+ {
+ g_print("Payload: Empty\n");
+ return;
+ }
+
+ len = net_nfc_get_data_length(data);
+
+ g_print ("Payload:\n");
+
+ for (i = 0; i < len; i++)
+ {
+ g_print("%02x", buffer[i]);
+ if ((i + 1) % 16 == 0)
+ g_print("\n");
+ else
+ g_print(" ");
+ }
+
+ g_print("\n");
+}
+