Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nfcd] Initial commit. JB#41661
  • Loading branch information
monich committed Nov 19, 2018
0 parents commit 0b3db05
Show file tree
Hide file tree
Showing 130 changed files with 24,363 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
build
26 changes: 26 additions & 0 deletions Makefile
@@ -0,0 +1,26 @@
# -*- Mode: makefile-gmake -*-
.PHONY: all clean install test

all:
@$(MAKE) -C src $@

test:
@$(MAKE) -C unit $@

install:
@$(MAKE) -C src $@
@$(MAKE) -C core $@
@$(MAKE) -C tools $@
@$(MAKE) -C plugins $@

clean:
@$(MAKE) -C src $@
@$(MAKE) -C core $@
@$(MAKE) -C tools $@
@$(MAKE) -C plugins $@
@$(MAKE) -C unit $@
rm -f *~ rpm/*~

.DEFAULT:
@$(MAKE) -C src $@
@$(MAKE) -C tools $@
200 changes: 200 additions & 0 deletions core/Makefile
@@ -0,0 +1,200 @@
# -*- Mode: makefile-gmake -*-

.PHONY: clean all debug release
.PHONY: print_debug_lib print_release_lib
.PHONY: print_debug_path print_release_path

#
# Required packages
#

PKGS = libglibutil glib-2.0 gobject-2.0

#
# Default target
#

all: debug release

#
# Library name
#

NAME = nfc-core
LIB_NAME = lib$(NAME)
LIB = $(LIB_NAME).a

#
# Sources
#

SRC = \
nfc_adapter.c \
nfc_crc.c \
nfc_manager.c \
nfc_ndef_rec.c \
nfc_ndef_rec_u.c \
nfc_plugins.c \
nfc_plugin.c \
nfc_tag.c \
nfc_tag_t2.c \
nfc_target.c \
nfc_tlv.c \
nfc_util.c

#
# Directories
#

SRC_DIR = src
INCLUDE_DIR = include
BUILD_DIR = build
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage

#
# Pull nfcd version from nfc_version.h file
#

VERSION_FILE = $(INCLUDE_DIR)/nfc_version.h
get_version = $(shell grep -E "^ *\\\#define +NFC_VERSION_$1 +[0-9]+$$" $(VERSION_FILE) | sed "s/ */ /g" | cut -d " " -f 3)

VERSION_MAJOR = $(call get_version,MAJOR)
VERSION_MINOR = $(call get_version,MINOR)
VERSION_RELEASE = $(call get_version,NANO)

# Version for pkg-config
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)

#
# Tools and flags
#

CC = $(CROSS_COMPILE)gcc
LD = $(CC)
WARNINGS = -Wall -Wstrict-aliasing -Wunused-result
INCLUDES = -I$(INCLUDE_DIR)
BASE_FLAGS = -fPIC
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
-MMD -MP $(shell pkg-config --cflags $(PKGS))
DEBUG_FLAGS = -g
RELEASE_FLAGS =
COVERAGE_FLAGS = -g

ifndef KEEP_SYMBOLS
KEEP_SYMBOLS = 0
endif

ifneq ($(KEEP_SYMBOLS),0)
RELEASE_FLAGS += -g
endif

DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
COVERAGE_CFLAGS = $(FULL_CFLAGS) $(COVERAGE_FLAGS) --coverage

#
# Files
#

PKGCONFIG_NAME = nfcd-plugin.pc
PKGCONFIG_TEMPLATE = $(PKGCONFIG_NAME).in
PKGCONFIG = $(BUILD_DIR)/$(PKGCONFIG_NAME)
DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
COVERAGE_OBJS = $(SRC:%.c=$(COVERAGE_BUILD_DIR)/%.o)


#
# Dependencies
#

DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
endif

$(DEBUG_OBJS) $(DEBUG_LIB): | $(DEBUG_BUILD_DIR)
$(RELEASE_OBJS) $(RELEASE_LIB): | $(RELEASE_BUILD_DIR)
$(COVERAGE_OBJS) $(COVERAGE_LIB): | $(COVERAGE_BUILD_DIR)

#
# Rules
#

DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB)
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)
COVERAGE_LIB = $(COVERAGE_BUILD_DIR)/$(LIB)

debug: $(DEBUG_LIB)

release: $(RELEASE_LIB)

debug_lib: $(DEBUG_LIB)

release_lib: $(RELEASE_LIB)

coverage_lib: $(COVERAGE_LIB)

clean:
rm -f *~ $(SRC_DIR)/*~ $(INCLUDE_DIR)/*~ $(INCLUDE_DIR)/internal/*~
rm -fr $(BUILD_DIR)

$(BUILD_DIR):
mkdir -p $@

$(DEBUG_BUILD_DIR):
mkdir -p $@

$(RELEASE_BUILD_DIR):
mkdir -p $@

$(COVERAGE_BUILD_DIR):
mkdir -p $@

$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(COVERAGE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(DEBUG_LIB): $(DEBUG_OBJS)
$(AR) rc $@ $?
ranlib $@

$(RELEASE_LIB): $(RELEASE_OBJS)
$(AR) rc $@ $?
ranlib $@

$(COVERAGE_LIB): $(COVERAGE_OBJS)
$(AR) rc $@ $?
ranlib $@

$(PKGCONFIG): $(PKGCONFIG_TEMPLATE) $(BUILD_DIR)
sed -e "s/\[version\]/$(PCVERSION)/g" $(PKGCONFIG_TEMPLATE) > $@

#
# Install
#

INSTALL = install
INSTALL_DIRS = $(INSTALL) -d

INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/nfcd
INSTALL_PKGCONFIG_DIR = $(DESTDIR)/usr/lib/pkgconfig

install: $(INSTALL_INCLUDE_DIR) $(INSTALL_PKGCONFIG_DIR) $(PKGCONFIG)
$(INSTALL) -m 644 $(INCLUDE_DIR)/*.h $(INSTALL_INCLUDE_DIR)
$(INSTALL) -m 644 $(PKGCONFIG) $(INSTALL_PKGCONFIG_DIR)

$(INSTALL_INCLUDE_DIR):
$(INSTALL_DIRS) $@

$(INSTALL_PKGCONFIG_DIR):
$(INSTALL_DIRS) $@
60 changes: 60 additions & 0 deletions core/include/internal/nfc_manager_i.h
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef NFC_MANAGER_INTERNAL_H
#define NFC_MANAGER_INTERNAL_H

#include <nfc_manager.h>

#include "nfc_types_i.h"

/* Add _ prefix so that they don't get exported */
#define nfc_manager_new _nfc_manager_new
#define nfc_manager_start _nfc_manager_start

NfcManager*
nfc_manager_new(
const NfcPluginsInfo* info);

gboolean
nfc_manager_start(
NfcManager* manager);

#endif /* NFC_MANAGER_INTERNAL_H */

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
57 changes: 57 additions & 0 deletions core/include/internal/nfc_types_i.h
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef NFC_TYPES_INTERNAL_H
#define NFC_TYPES_INTERNAL_H

#include <nfc_types.h>

typedef struct nfc_plugins_info {
const NfcPluginDesc* const* builtins;
const char* plugin_dir;
const char* const* enable;
const char* const* disable;
guint flags;

#define NFC_PLUGINS_DONT_UNLOAD (0x01)

} NfcPluginsInfo;

#endif /* NFC_TYPES_INTERNAL_H */

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/

0 comments on commit 0b3db05

Please sign in to comment.