upload android base code part4
This commit is contained in:
parent
b9e30e05b1
commit
78ea2404cd
23455 changed files with 5250148 additions and 0 deletions
73
android/hardware/interfaces/nfc/1.0/Android.bp
Normal file
73
android/hardware/interfaces/nfc/1.0/Android.bp
Normal file
|
@ -0,0 +1,73 @@
|
|||
// This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
filegroup {
|
||||
name: "android.hardware.nfc@1.0_hal",
|
||||
srcs: [
|
||||
"types.hal",
|
||||
"INfc.hal",
|
||||
"INfcClientCallback.hal",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.nfc@1.0_genc++",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.nfc@1.0",
|
||||
srcs: [
|
||||
":android.hardware.nfc@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/nfc/1.0/types.cpp",
|
||||
"android/hardware/nfc/1.0/NfcAll.cpp",
|
||||
"android/hardware/nfc/1.0/NfcClientCallbackAll.cpp",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.nfc@1.0_genc++_headers",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.nfc@1.0",
|
||||
srcs: [
|
||||
":android.hardware.nfc@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/nfc/1.0/types.h",
|
||||
"android/hardware/nfc/1.0/hwtypes.h",
|
||||
"android/hardware/nfc/1.0/INfc.h",
|
||||
"android/hardware/nfc/1.0/IHwNfc.h",
|
||||
"android/hardware/nfc/1.0/BnHwNfc.h",
|
||||
"android/hardware/nfc/1.0/BpHwNfc.h",
|
||||
"android/hardware/nfc/1.0/BsNfc.h",
|
||||
"android/hardware/nfc/1.0/INfcClientCallback.h",
|
||||
"android/hardware/nfc/1.0/IHwNfcClientCallback.h",
|
||||
"android/hardware/nfc/1.0/BnHwNfcClientCallback.h",
|
||||
"android/hardware/nfc/1.0/BpHwNfcClientCallback.h",
|
||||
"android/hardware/nfc/1.0/BsNfcClientCallback.h",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.nfc@1.0",
|
||||
defaults: ["hidl-module-defaults"],
|
||||
generated_sources: ["android.hardware.nfc@1.0_genc++"],
|
||||
generated_headers: ["android.hardware.nfc@1.0_genc++_headers"],
|
||||
export_generated_headers: ["android.hardware.nfc@1.0_genc++_headers"],
|
||||
vendor_available: true,
|
||||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
],
|
||||
export_shared_lib_headers: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"libutils",
|
||||
],
|
||||
}
|
237
android/hardware/interfaces/nfc/1.0/Android.mk
Normal file
237
android/hardware/interfaces/nfc/1.0/Android.mk
Normal file
|
@ -0,0 +1,237 @@
|
|||
# This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.nfc-V1.0-java
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := \
|
||||
android.hidl.base-V1.0-java \
|
||||
|
||||
|
||||
#
|
||||
# Build types.hal (NfcEvent)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/NfcEvent.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0::types.NfcEvent
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (NfcStatus)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/NfcStatus.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0::types.NfcStatus
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build INfc.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/INfc.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/INfc.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
$(GEN): $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0::INfc
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/INfc.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build INfcClientCallback.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/INfcClientCallback.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0::INfcClientCallback
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.nfc-V1.0-java-static
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
android.hidl.base-V1.0-java-static \
|
||||
|
||||
|
||||
#
|
||||
# Build types.hal (NfcEvent)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/NfcEvent.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0::types.NfcEvent
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (NfcStatus)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/NfcStatus.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0::types.NfcStatus
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build INfc.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/INfc.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/INfc.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
$(GEN): $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0::INfc
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/INfc.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build INfcClientCallback.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/INfcClientCallback.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0::INfcClientCallback
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.nfc-V1.0-java-constants
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/nfc/V1_0/Constants.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/INfc.hal
|
||||
$(GEN): $(LOCAL_PATH)/INfcClientCallback.hal
|
||||
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava-constants \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.nfc@1.0
|
||||
|
||||
$(GEN):
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
# Avoid dependency cycle of framework.jar -> this-library -> framework.jar
|
||||
LOCAL_NO_STANDARD_LIBRARIES := true
|
||||
LOCAL_JAVA_LIBRARIES := core-oj
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
|
||||
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
106
android/hardware/interfaces/nfc/1.0/INfc.hal
Normal file
106
android/hardware/interfaces/nfc/1.0/INfc.hal
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package android.hardware.nfc@1.0;
|
||||
|
||||
import INfcClientCallback;
|
||||
|
||||
interface INfc {
|
||||
/**
|
||||
* Opens the NFC controller device and performs initialization.
|
||||
* This may include patch download and other vendor-specific initialization.
|
||||
*
|
||||
* If open completes successfully, the controller should be ready to perform
|
||||
* NCI initialization - ie accept CORE_RESET and subsequent commands through
|
||||
* the write() call.
|
||||
*
|
||||
* If open() returns NfcStatus::OK, the NCI stack will wait for a
|
||||
* NfcEvent.OPEN_CPLT before continuing.
|
||||
*
|
||||
* If open() returns NfcStatus::FAILED, the NCI stack will stop.
|
||||
*
|
||||
*/
|
||||
@entry
|
||||
@callflow(next={"write", "coreInitialized", "prediscover", "powerCycle", "controlGranted"})
|
||||
open(INfcClientCallback clientCallback) generates (NfcStatus status);
|
||||
|
||||
/**
|
||||
* Performs an NCI write.
|
||||
*
|
||||
* This method may queue writes and return immediately. The only
|
||||
* requirement is that the writes are executed in order.
|
||||
*
|
||||
* @return number of bytes written to the NFCC
|
||||
*/
|
||||
@callflow(next={"write", "prediscover", "coreInitialized", "close", "powerCycle",
|
||||
"controlGranted"})
|
||||
write(NfcData data) generates (uint32_t retval);
|
||||
|
||||
/**
|
||||
* coreInitialized() is called after the CORE_INIT_RSP is received from the
|
||||
* NFCC. At this time, the HAL can do any chip-specific configuration.
|
||||
*
|
||||
* If coreInitialized() returns NfcStatus::OK, the NCI stack will wait for a
|
||||
* NfcEvent.POST_INIT_CPLT before continuing.
|
||||
*
|
||||
* If coreInitialized() returns NfcStatus::FAILED, the NCI stack will
|
||||
* continue immediately.
|
||||
*/
|
||||
@callflow(next={"write", "prediscover", "close"})
|
||||
coreInitialized(NfcData data) generates (NfcStatus status);
|
||||
|
||||
/**
|
||||
* prediscover is called every time before starting RF discovery.
|
||||
* It is a good place to do vendor-specific configuration that must be
|
||||
* performed every time RF discovery is about to be started.
|
||||
*
|
||||
* If prediscover() returns NfcStatus::OK, the NCI stack will wait for a
|
||||
* NfcEvent.PREDISCOVER_CPLT before continuing.
|
||||
*
|
||||
* If prediscover() returns NfcStatus::FAILED, the NCI stack will start
|
||||
* RF discovery immediately.
|
||||
*/
|
||||
@callflow(next={"write", "close", "coreInitialized", "powerCycle", "controlGranted"})
|
||||
prediscover() generates (NfcStatus status);
|
||||
|
||||
/**
|
||||
* Close the NFC controller. Should free all resources.
|
||||
*
|
||||
* @return NfcStatus::OK on success and NfcStatus::FAILED on error.
|
||||
*/
|
||||
@exit
|
||||
close() generates (NfcStatus status);
|
||||
|
||||
/**
|
||||
* Grant HAL the exclusive control to send NCI commands.
|
||||
* Called in response to NfcEvent.REQUEST_CONTROL.
|
||||
* Must only be called when there are no NCI commands pending.
|
||||
* NfcEvent.RELEASE_CONTROL will notify when HAL no longer needs exclusive control.
|
||||
*
|
||||
* @return NfcStatus::OK on success and NfcStatus::FAILED on error.
|
||||
*/
|
||||
@callflow(next={"write", "close", "prediscover", "coreInitialized", "powerCycle"})
|
||||
controlGranted() generates (NfcStatus status);
|
||||
|
||||
/**
|
||||
* Restart controller by power cyle;
|
||||
* NfcEvent.OPEN_CPLT will notify when operation is complete.
|
||||
*
|
||||
* @return NfcStatus::OK on success and NfcStatus::FAILED on error.
|
||||
*/
|
||||
@callflow(next={"write", "coreInitialized", "prediscover", "controlGranted", "close"})
|
||||
powerCycle() generates (NfcStatus status);
|
||||
};
|
31
android/hardware/interfaces/nfc/1.0/INfcClientCallback.hal
Normal file
31
android/hardware/interfaces/nfc/1.0/INfcClientCallback.hal
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package android.hardware.nfc@1.0;
|
||||
|
||||
interface INfcClientCallback {
|
||||
/**
|
||||
* The callback passed in from the NFC stack that the HAL
|
||||
* can use to pass events back to the stack.
|
||||
*/
|
||||
sendEvent(NfcEvent event, NfcStatus status);
|
||||
|
||||
/**
|
||||
* The callback passed in from the NFC stack that the HAL
|
||||
* can use to pass incomming data to the stack.
|
||||
*/
|
||||
sendData(NfcData data);
|
||||
};
|
39
android/hardware/interfaces/nfc/1.0/default/Android.bp
Normal file
39
android/hardware/interfaces/nfc/1.0/default/Android.bp
Normal file
|
@ -0,0 +1,39 @@
|
|||
cc_library_shared {
|
||||
name: "android.hardware.nfc@1.0-impl",
|
||||
defaults: ["hidl_defaults"],
|
||||
relative_install_path: "hw",
|
||||
proprietary: true,
|
||||
srcs: ["Nfc.cpp"],
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libhardware",
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"libutils",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"android.hardware.nfc@1.0",
|
||||
],
|
||||
}
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.nfc@1.0-service",
|
||||
relative_install_path: "hw",
|
||||
proprietary: true,
|
||||
init_rc: ["android.hardware.nfc@1.0-service.rc"],
|
||||
srcs: ["service.cpp"],
|
||||
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libdl",
|
||||
"libbase",
|
||||
"libutils",
|
||||
"libhardware",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"android.hardware.nfc@1.0",
|
||||
],
|
||||
|
||||
}
|
107
android/hardware/interfaces/nfc/1.0/default/Nfc.cpp
Normal file
107
android/hardware/interfaces/nfc/1.0/default/Nfc.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
#define LOG_TAG "android.hardware.nfc@1.0-impl"
|
||||
|
||||
#include <log/log.h>
|
||||
|
||||
#include <hardware/hardware.h>
|
||||
#include <hardware/nfc.h>
|
||||
#include "Nfc.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace nfc {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
sp<INfcClientCallback> Nfc::mCallback = nullptr;
|
||||
|
||||
Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device),
|
||||
mDeathRecipient(new NfcDeathRecipient(this)) {
|
||||
}
|
||||
|
||||
// Methods from ::android::hardware::nfc::V1_0::INfc follow.
|
||||
::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback) {
|
||||
mCallback = clientCallback;
|
||||
|
||||
if (mDevice == nullptr || mCallback == nullptr) {
|
||||
return NfcStatus::FAILED;
|
||||
}
|
||||
mCallback->linkToDeath(mDeathRecipient, 0 /*cookie*/);
|
||||
int ret = mDevice->open(mDevice, eventCallback, dataCallback);
|
||||
return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
|
||||
}
|
||||
|
||||
::android::hardware::Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data) {
|
||||
if (mDevice == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
return mDevice->write(mDevice, data.size(), &data[0]);
|
||||
}
|
||||
|
||||
::android::hardware::Return<NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) {
|
||||
hidl_vec<uint8_t> copy = data;
|
||||
|
||||
if (mDevice == nullptr) {
|
||||
return NfcStatus::FAILED;
|
||||
}
|
||||
int ret = mDevice->core_initialized(mDevice, ©[0]);
|
||||
return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
|
||||
}
|
||||
|
||||
::android::hardware::Return<NfcStatus> Nfc::prediscover() {
|
||||
if (mDevice == nullptr) {
|
||||
return NfcStatus::FAILED;
|
||||
}
|
||||
return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
|
||||
}
|
||||
|
||||
::android::hardware::Return<NfcStatus> Nfc::close() {
|
||||
if (mDevice == nullptr || mCallback == nullptr) {
|
||||
return NfcStatus::FAILED;
|
||||
}
|
||||
mCallback->unlinkToDeath(mDeathRecipient);
|
||||
return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
|
||||
}
|
||||
|
||||
::android::hardware::Return<NfcStatus> Nfc::controlGranted() {
|
||||
if (mDevice == nullptr) {
|
||||
return NfcStatus::FAILED;
|
||||
}
|
||||
return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
|
||||
}
|
||||
|
||||
::android::hardware::Return<NfcStatus> Nfc::powerCycle() {
|
||||
if (mDevice == nullptr) {
|
||||
return NfcStatus::FAILED;
|
||||
}
|
||||
return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
|
||||
}
|
||||
|
||||
|
||||
INfc* HIDL_FETCH_INfc(const char * /*name*/) {
|
||||
nfc_nci_device_t* nfc_device;
|
||||
int ret = 0;
|
||||
const hw_module_t* hw_module = nullptr;
|
||||
|
||||
ret = hw_get_module (NFC_NCI_HARDWARE_MODULE_ID, &hw_module);
|
||||
if (ret == 0) {
|
||||
ret = nfc_nci_open (hw_module, &nfc_device);
|
||||
if (ret != 0) {
|
||||
ALOGE ("nfc_nci_open failed: %d", ret);
|
||||
}
|
||||
}
|
||||
else
|
||||
ALOGE ("hw_get_module %s failed: %d", NFC_NCI_HARDWARE_MODULE_ID, ret);
|
||||
|
||||
if (ret == 0) {
|
||||
return new Nfc(nfc_device);
|
||||
} else {
|
||||
ALOGE("Passthrough failed to load legacy HAL.");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace nfc
|
||||
} // namespace hardware
|
||||
} // namespace android
|
76
android/hardware/interfaces/nfc/1.0/default/Nfc.h
Normal file
76
android/hardware/interfaces/nfc/1.0/default/Nfc.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
#ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H
|
||||
#define ANDROID_HARDWARE_NFC_V1_0_NFC_H
|
||||
|
||||
#include <android/hardware/nfc/1.0/INfc.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <hardware/hardware.h>
|
||||
#include <hardware/nfc.h>
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace nfc {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::nfc::V1_0::INfc;
|
||||
using ::android::hardware::nfc::V1_0::INfcClientCallback;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::hidl_string;
|
||||
using ::android::sp;
|
||||
|
||||
struct NfcDeathRecipient : hidl_death_recipient {
|
||||
NfcDeathRecipient(const sp<INfc> nfc) : mNfc(nfc) {
|
||||
}
|
||||
|
||||
virtual void serviceDied(uint64_t /*cookie*/, const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
|
||||
mNfc->close();
|
||||
}
|
||||
sp<INfc> mNfc;
|
||||
};
|
||||
|
||||
struct Nfc : public INfc {
|
||||
Nfc(nfc_nci_device_t* device);
|
||||
::android::hardware::Return<NfcStatus> open(const sp<INfcClientCallback>& clientCallback) override;
|
||||
::android::hardware::Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
|
||||
::android::hardware::Return<NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override;
|
||||
::android::hardware::Return<NfcStatus> prediscover() override;
|
||||
::android::hardware::Return<NfcStatus> close() override;
|
||||
::android::hardware::Return<NfcStatus> controlGranted() override;
|
||||
::android::hardware::Return<NfcStatus> powerCycle() override;
|
||||
|
||||
static void eventCallback(uint8_t event, uint8_t status) {
|
||||
if (mCallback != nullptr) {
|
||||
auto ret = mCallback->sendEvent(
|
||||
(::android::hardware::nfc::V1_0::NfcEvent) event,
|
||||
(::android::hardware::nfc::V1_0::NfcStatus) status);
|
||||
if (!ret.isOk()) {
|
||||
ALOGW("Failed to call back into NFC process.");
|
||||
}
|
||||
}
|
||||
}
|
||||
static void dataCallback(uint16_t data_len, uint8_t* p_data) {
|
||||
hidl_vec<uint8_t> data;
|
||||
data.setToExternal(p_data, data_len);
|
||||
if (mCallback != nullptr) {
|
||||
auto ret = mCallback->sendData(data);
|
||||
if (!ret.isOk()) {
|
||||
ALOGW("Failed to call back into NFC process.");
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
static sp<INfcClientCallback> mCallback;
|
||||
const nfc_nci_device_t* mDevice;
|
||||
sp<NfcDeathRecipient> mDeathRecipient;
|
||||
};
|
||||
|
||||
extern "C" INfc* HIDL_FETCH_INfc(const char* name);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace nfc
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H
|
2
android/hardware/interfaces/nfc/1.0/default/OWNERS
Normal file
2
android/hardware/interfaces/nfc/1.0/default/OWNERS
Normal file
|
@ -0,0 +1,2 @@
|
|||
eisenbach@google.com
|
||||
kandoiruchi@google.com
|
|
@ -0,0 +1,4 @@
|
|||
service nfc_hal_service /vendor/bin/hw/android.hardware.nfc@1.0-service
|
||||
class hal
|
||||
user nfc
|
||||
group nfc
|
13
android/hardware/interfaces/nfc/1.0/default/service.cpp
Normal file
13
android/hardware/interfaces/nfc/1.0/default/service.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#define LOG_TAG "android.hardware.nfc@1.0-service"
|
||||
|
||||
#include <android/hardware/nfc/1.0/INfc.h>
|
||||
|
||||
#include <hidl/LegacySupport.h>
|
||||
|
||||
// Generated HIDL files
|
||||
using android::hardware::nfc::V1_0::INfc;
|
||||
using android::hardware::defaultPassthroughServiceImplementation;
|
||||
|
||||
int main() {
|
||||
return defaultPassthroughServiceImplementation<INfc>();
|
||||
}
|
39
android/hardware/interfaces/nfc/1.0/types.hal
Normal file
39
android/hardware/interfaces/nfc/1.0/types.hal
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package android.hardware.nfc@1.0;
|
||||
|
||||
@export(name="", value_prefix="HAL_NFC_", value_suffix="_EVT")
|
||||
enum NfcEvent : uint32_t {
|
||||
OPEN_CPLT = 0,
|
||||
CLOSE_CPLT = 1,
|
||||
POST_INIT_CPLT = 2,
|
||||
PRE_DISCOVER_CPLT = 3,
|
||||
REQUEST_CONTROL = 4,
|
||||
RELEASE_CONTROL = 5,
|
||||
ERROR = 6
|
||||
};
|
||||
|
||||
@export(name="", value_prefix="HAL_NFC_STATUS_")
|
||||
enum NfcStatus : uint32_t {
|
||||
OK = 0,
|
||||
FAILED = 1,
|
||||
ERR_TRANSPORT = 2,
|
||||
ERR_CMD_TIMEOUT = 3,
|
||||
REFUSED = 4
|
||||
};
|
||||
|
||||
typedef vec<uint8_t> NfcData;
|
19
android/hardware/interfaces/nfc/1.0/vts/Android.mk
Normal file
19
android/hardware/interfaces/nfc/1.0/vts/Android.mk
Normal file
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
# Copyright (C) 2016 The Android Open Source Project
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(call all-subdir-makefiles)
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
cc_test {
|
||||
name: "VtsHalNfcV1_0TargetTest",
|
||||
defaults: ["VtsHalTargetTestDefaults"],
|
||||
srcs: ["VtsHalNfcV1_0TargetTest.cpp"],
|
||||
static_libs: [
|
||||
"android.hardware.nfc@1.0",
|
||||
],
|
||||
}
|
|
@ -0,0 +1,602 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "nfc_hidl_hal_test"
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <android/hardware/nfc/1.0/INfc.h>
|
||||
#include <android/hardware/nfc/1.0/INfcClientCallback.h>
|
||||
#include <android/hardware/nfc/1.0/types.h>
|
||||
#include <hardware/nfc.h>
|
||||
|
||||
#include <VtsHalHidlTargetCallbackBase.h>
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
|
||||
using ::android::hardware::nfc::V1_0::INfc;
|
||||
using ::android::hardware::nfc::V1_0::INfcClientCallback;
|
||||
using ::android::hardware::nfc::V1_0::NfcEvent;
|
||||
using ::android::hardware::nfc::V1_0::NfcStatus;
|
||||
using ::android::hardware::nfc::V1_0::NfcData;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::sp;
|
||||
|
||||
/* NCI Commands */
|
||||
#define CORE_RESET_CMD \
|
||||
{ 0x20, 0x00, 0x01, 0x00 }
|
||||
#define CORE_RESET_CMD_CONFIG_RESET \
|
||||
{ 0x20, 0x00, 0x01, 0x01 }
|
||||
#define CORE_CONN_CREATE_CMD \
|
||||
{ 0x20, 0x04, 0x02, 0x01, 0x00 }
|
||||
#define CORE_INIT_CMD \
|
||||
{ 0x20, 0x01, 0x00 }
|
||||
#define CORE_INIT_CMD_NCI20 \
|
||||
{ 0x20, 0x01, 0x02, 0x00, 0x00 }
|
||||
#define INVALID_COMMAND \
|
||||
{ 0x20, 0x00, 0x00 }
|
||||
|
||||
#define LOOP_BACK_HEADER_SIZE 3
|
||||
#define SYNTAX_ERROR 5
|
||||
#define NUMBER_LOOPS 3922
|
||||
#define NCI_VERSION_1_1 0x11
|
||||
#define NCI_VERSION_2 0x20
|
||||
#define TIMEOUT_PERIOD 5
|
||||
|
||||
constexpr char kCallbackNameSendEvent[] = "sendEvent";
|
||||
constexpr char kCallbackNameSendData[] = "sendData";
|
||||
|
||||
class NfcClientCallbackArgs {
|
||||
public:
|
||||
NfcEvent last_event_;
|
||||
NfcStatus last_status_;
|
||||
NfcData last_data_;
|
||||
};
|
||||
|
||||
/* Callback class for data & Event. */
|
||||
class NfcClientCallback
|
||||
: public ::testing::VtsHalHidlTargetCallbackBase<NfcClientCallbackArgs>,
|
||||
public INfcClientCallback {
|
||||
public:
|
||||
virtual ~NfcClientCallback() = default;
|
||||
|
||||
/* sendEvent callback function - Records the Event & Status
|
||||
* and notifies the TEST
|
||||
**/
|
||||
Return<void> sendEvent(NfcEvent event, NfcStatus event_status) override {
|
||||
NfcClientCallbackArgs args;
|
||||
args.last_event_ = event;
|
||||
args.last_status_ = event_status;
|
||||
NotifyFromCallback(kCallbackNameSendEvent, args);
|
||||
return Void();
|
||||
};
|
||||
|
||||
/* sendData callback function. Records the data and notifies the TEST*/
|
||||
Return<void> sendData(const NfcData& data) override {
|
||||
NfcClientCallbackArgs args;
|
||||
args.last_data_ = data;
|
||||
NotifyFromCallback(kCallbackNameSendData, args);
|
||||
return Void();
|
||||
};
|
||||
};
|
||||
|
||||
// The main test class for NFC HIDL HAL.
|
||||
class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
nfc_ = ::testing::VtsHalHidlTargetTestBase::getService<INfc>();
|
||||
ASSERT_NE(nfc_, nullptr);
|
||||
|
||||
nfc_cb_ = new NfcClientCallback();
|
||||
ASSERT_NE(nfc_cb_, nullptr);
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
|
||||
// Wait for OPEN_CPLT event
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
|
||||
/* Get the NCI version that the device supports */
|
||||
std::vector<uint8_t> cmd = CORE_RESET_CMD;
|
||||
NfcData data = cmd;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_RESET_RSP
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_GE(6ul, res.args->last_data_.size());
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
if (res.args->last_data_.size() == 6) {
|
||||
nci_version = res.args->last_data_[4];
|
||||
} else {
|
||||
EXPECT_EQ(4ul, res.args->last_data_.size());
|
||||
nci_version = NCI_VERSION_2;
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close the hal and then re-open to make sure we are in a predictable
|
||||
* state for all the tests.
|
||||
*/
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->close());
|
||||
// Wait for CLOSE_CPLT event
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
|
||||
// Wait for OPEN_CPLT event
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
}
|
||||
|
||||
virtual void TearDown() override {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->close());
|
||||
// Wait for CLOSE_CPLT event
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
}
|
||||
|
||||
/* NCI version the device supports
|
||||
* 0x11 for NCI 1.1, 0x20 for NCI 2.0 and so forth */
|
||||
uint8_t nci_version;
|
||||
sp<INfc> nfc_;
|
||||
sp<NfcClientCallback> nfc_cb_;
|
||||
};
|
||||
|
||||
// A class for test environment setup (kept since this file is a template).
|
||||
class NfcHidlEnvironment : public ::testing::Environment {
|
||||
public:
|
||||
virtual void SetUp() {}
|
||||
virtual void TearDown() {}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
/*
|
||||
* OpenAndClose:
|
||||
* Makes an open call, waits for NfcEvent.OPEN_CPLT
|
||||
* Immediately calls close() and waits for NfcEvent.CLOSE_CPLT
|
||||
* Since open and close calls are a part of SetUp() and TearDown(),
|
||||
* the function definition is intentionally kept empty
|
||||
*/
|
||||
TEST_F(NfcHidlTest, OpenAndClose) {}
|
||||
|
||||
/*
|
||||
* WriteCoreReset:
|
||||
* Sends CORE_RESET_CMD
|
||||
* Waits for CORE_RESET_RSP
|
||||
* Checks the status, version number and configuration status
|
||||
*/
|
||||
TEST_F(NfcHidlTest, WriteCoreReset) {
|
||||
std::vector<uint8_t> cmd = CORE_RESET_CMD;
|
||||
NfcData data = cmd;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_RESET_RSP
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
|
||||
/* The response/notification format for CORE_RESET_CMD differs
|
||||
* with NCI 1.0 and 2.0. */
|
||||
if (nci_version <= NCI_VERSION_1_1) {
|
||||
EXPECT_EQ(6ul, res.args->last_data_.size());
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
EXPECT_GE(NCI_VERSION_1_1, res.args->last_data_[4]);
|
||||
EXPECT_GE(1ul, res.args->last_data_[5]);
|
||||
} else {
|
||||
EXPECT_EQ(4ul, res.args->last_data_.size());
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
// Wait for CORE_RESET_NTF
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
// Check if reset trigger was due to CORE_RESET_CMD
|
||||
EXPECT_LE(8ul, res.args->last_data_.size());
|
||||
EXPECT_EQ(2ul, res.args->last_data_[3]);
|
||||
EXPECT_GE(1ul, res.args->last_data_[4]);
|
||||
EXPECT_EQ(NCI_VERSION_2, res.args->last_data_[5]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WriteCoreResetConfigReset:
|
||||
* Sends CORE_RESET_CMD_CONFIG_RESET
|
||||
* Waits for CORE_RESET_RSP
|
||||
* Checks the status, version number and configuration status
|
||||
*/
|
||||
TEST_F(NfcHidlTest, WriteCoreResetConfigReset) {
|
||||
std::vector<uint8_t> cmd = CORE_RESET_CMD_CONFIG_RESET;
|
||||
NfcData data = cmd;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_RESET_RSP
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
|
||||
/* The response/notification format for CORE_RESET_CMD differs
|
||||
* with NCI 1.0 and 2.0. */
|
||||
if (nci_version <= NCI_VERSION_1_1) {
|
||||
EXPECT_EQ(6ul, res.args->last_data_.size());
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
EXPECT_GE(NCI_VERSION_1_1, res.args->last_data_[4]);
|
||||
EXPECT_EQ(1ul, res.args->last_data_[5]);
|
||||
} else {
|
||||
EXPECT_EQ(4ul, res.args->last_data_.size());
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
// Wait for CORE_RESET_NTF
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
// Check if reset trigger was due to CORE_RESET_CMD
|
||||
EXPECT_LE(8ul, res.args->last_data_.size());
|
||||
EXPECT_EQ(2ul, res.args->last_data_[3]);
|
||||
EXPECT_EQ(1ul, res.args->last_data_[4]);
|
||||
EXPECT_EQ(NCI_VERSION_2, res.args->last_data_[5]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WriteInvalidCommand:
|
||||
* Sends an invalid command
|
||||
* Waits for response
|
||||
* Checks SYNTAX_ERROR status
|
||||
*/
|
||||
TEST_F(NfcHidlTest, WriteInvalidCommand) {
|
||||
// Send an Error Command
|
||||
std::vector<uint8_t> cmd = INVALID_COMMAND;
|
||||
NfcData data = cmd;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for RSP
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(4ul, res.args->last_data_.size());
|
||||
EXPECT_EQ(SYNTAX_ERROR, res.args->last_data_[3]);
|
||||
}
|
||||
|
||||
/*
|
||||
* WriteInvalidAndThenValidCommand:
|
||||
* Sends an Invalid command
|
||||
* Waits for response
|
||||
* Checks SYNTAX_ERROR status
|
||||
* Repeat for 100 times appending 0xFF each time to the packet
|
||||
* Send CORE_CONN_CREATE_CMD for loop-back mode
|
||||
* Check the response
|
||||
*/
|
||||
TEST_F(NfcHidlTest, WriteInvalidAndThenValidCommand) {
|
||||
std::vector<uint8_t> cmd = CORE_RESET_CMD;
|
||||
NfcData data = cmd;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_RESET_RSP
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
|
||||
/* NCI 2.0 sends CORE_RESET_NTF everytime. */
|
||||
if (nci_version == NCI_VERSION_2) {
|
||||
// Wait for CORE_RESET_NTF
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
cmd = CORE_INIT_CMD_NCI20;
|
||||
} else {
|
||||
cmd = CORE_INIT_CMD;
|
||||
}
|
||||
data = cmd;
|
||||
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_INIT_RSP
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
if (nci_version == NCI_VERSION_2 && res.args->last_data_.size() > 13 &&
|
||||
res.args->last_data_[13] == 0x00) {
|
||||
// Wait for CORE_CONN_CREDITS_NTF
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
}
|
||||
// Send an Error Data Packet
|
||||
cmd = INVALID_COMMAND;
|
||||
data = cmd;
|
||||
size_t size = data.size();
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
data.resize(++size);
|
||||
data[size - 1] = 0xFF;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for response with SYNTAX_ERROR
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(4ul, res.args->last_data_.size());
|
||||
EXPECT_EQ(SYNTAX_ERROR, res.args->last_data_[3]);
|
||||
}
|
||||
|
||||
cmd = CORE_CONN_CREATE_CMD;
|
||||
data = cmd;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_CONN_CREATE_RSP
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(7ul, res.args->last_data_.size());
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
}
|
||||
/*
|
||||
* Bandwidth:
|
||||
* Sets the loop-back mode using CORE_CONN_CREATE_CMD
|
||||
* Sends max payload size data
|
||||
* Waits for the response
|
||||
* Checks the data received
|
||||
* Repeat to send total of 1Mb data
|
||||
*/
|
||||
TEST_F(NfcHidlTest, Bandwidth) {
|
||||
std::vector<uint8_t> cmd = CORE_RESET_CMD;
|
||||
NfcData data = cmd;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_RESET_RSP
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
|
||||
/* NCI 2.0 sends CORE_RESET_NTF everytime. */
|
||||
if (nci_version == NCI_VERSION_2) {
|
||||
// Wait for CORE_RESET_NTF
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
cmd = CORE_INIT_CMD_NCI20;
|
||||
} else {
|
||||
cmd = CORE_INIT_CMD;
|
||||
}
|
||||
data = cmd;
|
||||
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_INIT_RSP
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
if (nci_version == NCI_VERSION_2 && res.args->last_data_.size() > 13 &&
|
||||
res.args->last_data_[13] == 0x00) {
|
||||
// Wait for CORE_CONN_CREDITS_NTF
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
}
|
||||
|
||||
cmd = CORE_CONN_CREATE_CMD;
|
||||
data = cmd;
|
||||
EXPECT_EQ(data.size(), nfc_->write(data));
|
||||
// Wait for CORE_CONN_CREATE_RSP
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(7ul, res.args->last_data_.size());
|
||||
EXPECT_EQ((int)NfcStatus::OK, res.args->last_data_[3]);
|
||||
uint8_t conn_id = res.args->last_data_[6];
|
||||
uint32_t max_payload_size = res.args->last_data_[4];
|
||||
|
||||
for (int loops = 0; loops < NUMBER_LOOPS; loops++) {
|
||||
res.args->last_data_.resize(0);
|
||||
data.resize(max_payload_size + LOOP_BACK_HEADER_SIZE);
|
||||
data[0] = conn_id;
|
||||
data[1] = 0x00;
|
||||
data[2] = max_payload_size;
|
||||
for (uint32_t i = 0; i < max_payload_size; i++) {
|
||||
data[i + LOOP_BACK_HEADER_SIZE] = i;
|
||||
}
|
||||
EXPECT_EQ(max_payload_size + LOOP_BACK_HEADER_SIZE, nfc_->write(data));
|
||||
// Wait for data and CORE_CONN_CREDITS_NTF
|
||||
auto res1 = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res1.no_timeout);
|
||||
auto res2 = nfc_cb_->WaitForCallback(kCallbackNameSendData);
|
||||
EXPECT_TRUE(res2.no_timeout);
|
||||
// Check if the same data was received back
|
||||
EXPECT_TRUE(res1.args);
|
||||
EXPECT_TRUE(res2.args);
|
||||
|
||||
NfcData credits_ntf = res1.args->last_data_;
|
||||
NfcData received_data = res2.args->last_data_;
|
||||
/* It is possible that CORE_CONN_CREDITS_NTF is received before data,
|
||||
* Find the order and do further checks depending on that */
|
||||
if (received_data.size() != data.size()) {
|
||||
credits_ntf = res2.args->last_data_;
|
||||
received_data = res1.args->last_data_;
|
||||
}
|
||||
EXPECT_EQ(data.size(), received_data.size());
|
||||
for (size_t i = 0; i < data.size(); i++) {
|
||||
EXPECT_EQ(data[i], received_data[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(6ul, credits_ntf.size());
|
||||
// Check if the credit is refilled to 1
|
||||
EXPECT_EQ(1, credits_ntf[5]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* PowerCycle:
|
||||
* Calls powerCycle()
|
||||
* Waits for NfcEvent.OPEN_CPLT
|
||||
* Checks status
|
||||
*/
|
||||
TEST_F(NfcHidlTest, PowerCycle) {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->powerCycle());
|
||||
// Wait for NfcEvent.OPEN_CPLT
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
}
|
||||
|
||||
/*
|
||||
* PowerCycleAfterClose:
|
||||
* Calls powerCycle() after close()
|
||||
* Checks status
|
||||
*/
|
||||
TEST_F(NfcHidlTest, PowerCycleAfterClose) {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->close());
|
||||
// Wait for CLOSE_CPLT event
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
|
||||
EXPECT_EQ(NfcStatus::FAILED, nfc_->powerCycle());
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
|
||||
// Wait for OPEN_CPLT event
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
}
|
||||
|
||||
/*
|
||||
* CoreInitialized:
|
||||
* Calls coreInitialized() with different data
|
||||
* Waits for NfcEvent.POST_INIT_CPLT
|
||||
*/
|
||||
TEST_F(NfcHidlTest, CoreInitialized) {
|
||||
NfcData data;
|
||||
data.resize(1);
|
||||
// These parameters might lead to device specific proprietary behavior
|
||||
// Using > 10 values should result in predictable and common results for
|
||||
// most devices.
|
||||
for (int i = 10; i <= 16; i++) {
|
||||
data[0] = i;
|
||||
NfcStatus status = nfc_->coreInitialized(data);
|
||||
|
||||
/* In case coreInitialized returned FAILED, do not wait for
|
||||
* POST_INIT_CLPT event. */
|
||||
if (status == NfcStatus::FAILED) continue;
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, status);
|
||||
// Wait for NfcEvent.POST_INIT_CPLT
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::POST_INIT_CPLT, res.args->last_event_);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ControlGranted:
|
||||
* Calls controlGranted()
|
||||
* Checks the return value
|
||||
*/
|
||||
TEST_F(NfcHidlTest, ControlGranted) {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->controlGranted());
|
||||
}
|
||||
|
||||
/*
|
||||
* ControlGrantedAfterClose:
|
||||
* Call controlGranted() after close
|
||||
* Checks the return value
|
||||
*/
|
||||
TEST_F(NfcHidlTest, ControlGrantedAfterClose) {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->close());
|
||||
// Wait for CLOSE_CPLT event
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->controlGranted());
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
|
||||
// Wait for OPEN_CPLT event
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
}
|
||||
|
||||
/* PreDiscover:
|
||||
* Calls prediscover()
|
||||
* Checks the return value
|
||||
*/
|
||||
TEST_F(NfcHidlTest, PreDiscover) {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->prediscover());
|
||||
}
|
||||
|
||||
/*
|
||||
* PreDiscoverAfterClose:
|
||||
* Call prediscover() after close
|
||||
* Checks the return value
|
||||
*/
|
||||
TEST_F(NfcHidlTest, PreDiscoverAfterClose) {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->close());
|
||||
// Wait for CLOSE_CPLT event
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->prediscover());
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
|
||||
// Wait for OPEN_CPLT event
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
}
|
||||
|
||||
/*
|
||||
* CloseAfterClose:
|
||||
* Calls close() multiple times
|
||||
* Checks status
|
||||
*/
|
||||
TEST_F(NfcHidlTest, CloseAfterClose) {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->close());
|
||||
// Wait for CLOSE_CPLT event
|
||||
auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
|
||||
EXPECT_EQ(NfcStatus::FAILED, nfc_->close());
|
||||
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
|
||||
// Wait for OPEN_CPLT event
|
||||
res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
|
||||
EXPECT_TRUE(res.no_timeout);
|
||||
EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
|
||||
EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
|
||||
}
|
||||
|
||||
/*
|
||||
* OpenAfterOpen:
|
||||
* Calls open() multiple times
|
||||
* Checks status
|
||||
*/
|
||||
TEST_F(NfcHidlTest, OpenAfterOpen) {
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
|
||||
EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::AddGlobalTestEnvironment(new NfcHidlEnvironment);
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
std::system("svc nfc disable"); /* Turn off NFC */
|
||||
sleep(5);
|
||||
|
||||
int status = RUN_ALL_TESTS();
|
||||
LOG(INFO) << "Test result = " << status;
|
||||
|
||||
std::system("svc nfc enable"); /* Turn on NFC */
|
||||
sleep(5);
|
||||
|
||||
return status;
|
||||
}
|
6
android/hardware/interfaces/nfc/Android.bp
Normal file
6
android/hardware/interfaces/nfc/Android.bp
Normal file
|
@ -0,0 +1,6 @@
|
|||
// This is an autogenerated file, do not edit.
|
||||
subdirs = [
|
||||
"1.0",
|
||||
"1.0/default",
|
||||
"1.0/vts/functional",
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue