Iliyan Malchev | 3db0f60 | 2016-09-26 09:57:20 -0700 | [diff] [blame^] | 1 | #define LOG_TAG "android.hardware.nfc@1.0-impl" |
| 2 | #include <utils/Log.h> |
| 3 | |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 4 | #include <hardware/hardware.h> |
| 5 | #include <hardware/nfc.h> |
| 6 | #include "Nfc.h" |
| 7 | |
| 8 | namespace android { |
| 9 | namespace hardware { |
| 10 | namespace nfc { |
| 11 | namespace V1_0 { |
| 12 | namespace implementation { |
| 13 | |
| 14 | sp<INfcClientCallback> Nfc::mCallback = NULL; |
| 15 | |
| 16 | Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) { |
| 17 | } |
| 18 | |
| 19 | // Methods from ::android::hardware::nfc::V1_0::INfc follow. |
| 20 | ::android::hardware::Return<int32_t> Nfc::open(const sp<INfcClientCallback>& clientCallback) { |
| 21 | mCallback = clientCallback; |
| 22 | return mDevice->open(mDevice, event_callback, data_callback); |
| 23 | } |
| 24 | |
| 25 | ::android::hardware::Return<int32_t> Nfc::write(const nfc_data_t& data) { |
| 26 | return mDevice->write(mDevice, data.data.size(), &data.data[0]); |
| 27 | } |
| 28 | |
| 29 | ::android::hardware::Return<int32_t> Nfc::core_initialized(const hidl_vec<uint8_t>& data) { |
| 30 | hidl_vec<uint8_t> copy = data; |
| 31 | return mDevice->core_initialized(mDevice, ©[0]); |
| 32 | } |
| 33 | |
| 34 | ::android::hardware::Return<int32_t> Nfc::pre_discover() { |
| 35 | return mDevice->pre_discover(mDevice); |
| 36 | } |
| 37 | |
| 38 | ::android::hardware::Return<int32_t> Nfc::close() { |
| 39 | return mDevice->close(mDevice); |
| 40 | } |
| 41 | |
| 42 | ::android::hardware::Return<int32_t> Nfc::control_granted() { |
| 43 | return mDevice->control_granted(mDevice); |
| 44 | } |
| 45 | |
| 46 | ::android::hardware::Return<int32_t> Nfc::power_cycle() { |
| 47 | return mDevice->power_cycle(mDevice); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | INfc* HIDL_FETCH_INfc(const char *hal) { |
| 52 | nfc_nci_device_t* nfc_device; |
| 53 | int ret = 0; |
| 54 | const hw_module_t* hw_module = NULL; |
| 55 | |
| 56 | ret = hw_get_module (hal, &hw_module); |
| 57 | if (ret == 0) |
| 58 | { |
| 59 | ret = nfc_nci_open (hw_module, &nfc_device); |
| 60 | if (ret != 0) { |
| 61 | ALOGE ("nfc_nci_open %s failed: %d", hal, ret); |
| 62 | } |
| 63 | } |
| 64 | else |
| 65 | ALOGE ("hw_get_module %s failed: %d", hal, ret); |
| 66 | |
| 67 | if (ret == 0) { |
| 68 | return new Nfc(nfc_device); |
| 69 | } else { |
| 70 | ALOGE("Passthrough failed to load legacy HAL."); |
| 71 | return nullptr; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | } // namespace implementation |
| 76 | } // namespace V1_0 |
| 77 | } // namespace nfc |
| 78 | } // namespace hardware |
| 79 | } // namespace android |