diff --git a/nfc/1.0/INfc.hal b/nfc/1.0/INfc.hal index 1c952dbac8..c6e151195c 100644 --- a/nfc/1.0/INfc.hal +++ b/nfc/1.0/INfc.hal @@ -27,72 +27,80 @@ interface INfc { * NCI initialization - ie accept CORE_RESET and subsequent commands through * the write() call. * - * If open() returns 0, the NCI stack will wait for a NfcEvent.OPEN_CPLT - * before continuing. + * If open() returns NfcStatus::OK, the NCI stack will wait for a + * NfcEvent.OPEN_CPLT before continuing. * - * If open() returns any other value, the NCI stack will stop. + * If open() returns NfcStatus::FAILED, the NCI stack will stop. * */ @entry @callflow(next={"write", "coreInitialized", "prediscover", "powerCycle", "controlGranted"}) - open(INfcClientCallback clientCallback) generates (int32_t retval); + 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 (int32_t retval); + 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. + * 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 0, the NCI stack will wait for a NfcEvent.POST_INIT_CPLT - * before continuing. + * If coreInitialized() returns NfcStatus::OK, the NCI stack will wait for a + * NfcEvent.POST_INIT_CPLT before continuing. * - * If coreInitialized() returns any other value, the NCI stack will continue - * immediately. + * If coreInitialized() returns NfcStatus::FAILED, the NCI stack will + * continue immediately. */ @callflow(next={"write", "prediscover", "close"}) - coreInitialized(NfcData data) generates (int32_t retval); + 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 0, the NCI stack will wait for a NfcEvent.PREDISCOVER_CPLT - * before continuing. + * If prediscover() returns NfcStatus::OK, the NCI stack will wait for a + * NfcEvent.PREDISCOVER_CPLT before continuing. * - * If prediscover() returns any other value, the NCI stack will start + * If prediscover() returns NfcStatus::FAILED, the NCI stack will start * RF discovery immediately. */ @callflow(next={"write", "close", "coreInitialized", "powerCycle", "controlGranted"}) - prediscover() generates (int32_t retval); + 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 (int32_t retval); + 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 (int32_t retval); + 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 (int32_t retval); + powerCycle() generates (NfcStatus status); }; diff --git a/nfc/1.0/default/Nfc.cpp b/nfc/1.0/default/Nfc.cpp index d3868c1309..bee374d587 100644 --- a/nfc/1.0/default/Nfc.cpp +++ b/nfc/1.0/default/Nfc.cpp @@ -17,34 +17,36 @@ Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) { } // Methods from ::android::hardware::nfc::V1_0::INfc follow. -::android::hardware::Return Nfc::open(const sp& clientCallback) { +::android::hardware::Return Nfc::open(const sp& clientCallback) { mCallback = clientCallback; - return mDevice->open(mDevice, eventCallback, dataCallback); + int ret = mDevice->open(mDevice, eventCallback, dataCallback); + return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED; } -::android::hardware::Return Nfc::write(const hidl_vec& data) { +::android::hardware::Return Nfc::write(const hidl_vec& data) { return mDevice->write(mDevice, data.size(), &data[0]); } -::android::hardware::Return Nfc::coreInitialized(const hidl_vec& data) { +::android::hardware::Return Nfc::coreInitialized(const hidl_vec& data) { hidl_vec copy = data; - return mDevice->core_initialized(mDevice, ©[0]); + int ret = mDevice->core_initialized(mDevice, ©[0]); + return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED; } -::android::hardware::Return Nfc::prediscover() { - return mDevice->pre_discover(mDevice); +::android::hardware::Return Nfc::prediscover() { + return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; } -::android::hardware::Return Nfc::close() { - return mDevice->close(mDevice); +::android::hardware::Return Nfc::close() { + return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; } -::android::hardware::Return Nfc::controlGranted() { - return mDevice->control_granted(mDevice); +::android::hardware::Return Nfc::controlGranted() { + return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; } -::android::hardware::Return Nfc::powerCycle() { - return mDevice->power_cycle(mDevice); +::android::hardware::Return Nfc::powerCycle() { + return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; } diff --git a/nfc/1.0/default/Nfc.h b/nfc/1.0/default/Nfc.h index 5257636b69..13004a502b 100644 --- a/nfc/1.0/default/Nfc.h +++ b/nfc/1.0/default/Nfc.h @@ -21,13 +21,13 @@ using ::android::sp; struct Nfc : public INfc { Nfc(nfc_nci_device_t* device); - ::android::hardware::Return open(const sp& clientCallback) override; - ::android::hardware::Return write(const hidl_vec& data) override; - ::android::hardware::Return coreInitialized(const hidl_vec& data) override; - ::android::hardware::Return prediscover() override; - ::android::hardware::Return close() override; - ::android::hardware::Return controlGranted() override; - ::android::hardware::Return powerCycle() override; + ::android::hardware::Return open(const sp& clientCallback) override; + ::android::hardware::Return write(const hidl_vec& data) override; + ::android::hardware::Return coreInitialized(const hidl_vec& data) override; + ::android::hardware::Return prediscover() override; + ::android::hardware::Return close() override; + ::android::hardware::Return controlGranted() override; + ::android::hardware::Return powerCycle() override; static void eventCallback(uint8_t event, uint8_t status) { if (mCallback != nullptr) {