The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2011-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | #pragma once |
| 19 | #include <pthread.h> |
Ruchi Kandoi | 3800a82 | 2016-12-12 16:49:49 -0800 | [diff] [blame] | 20 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 21 | #include "nfc_hal_api.h" |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 22 | #include "nfc_target.h" |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 23 | |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace nfc { |
| 29 | namespace V1_0 { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 30 | struct INfc; |
| 31 | struct INfcClientCallback; |
| 32 | } |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame^] | 33 | namespace V1_1 { |
| 34 | struct INfc; |
| 35 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 39 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 40 | class ThreadMutex { |
| 41 | public: |
| 42 | ThreadMutex(); |
| 43 | virtual ~ThreadMutex(); |
| 44 | void lock(); |
| 45 | void unlock(); |
| 46 | operator pthread_mutex_t*() { return &mMutex; } |
| 47 | |
| 48 | private: |
| 49 | pthread_mutex_t mMutex; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 52 | class ThreadCondVar : public ThreadMutex { |
| 53 | public: |
| 54 | ThreadCondVar(); |
| 55 | virtual ~ThreadCondVar(); |
| 56 | void signal(); |
| 57 | void wait(); |
| 58 | operator pthread_cond_t*() { return &mCondVar; } |
| 59 | operator pthread_mutex_t*() { |
| 60 | return ThreadMutex::operator pthread_mutex_t*(); |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | pthread_cond_t mCondVar; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 67 | class AutoThreadMutex { |
| 68 | public: |
| 69 | AutoThreadMutex(ThreadMutex& m); |
| 70 | virtual ~AutoThreadMutex(); |
| 71 | operator ThreadMutex&() { return mm; } |
| 72 | operator pthread_mutex_t*() { return (pthread_mutex_t*)mm; } |
| 73 | |
| 74 | private: |
| 75 | ThreadMutex& mm; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 78 | class NfcAdaptation { |
| 79 | public: |
| 80 | virtual ~NfcAdaptation(); |
| 81 | void Initialize(); |
| 82 | void Finalize(); |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame^] | 83 | void FactoryReset(); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 84 | static NfcAdaptation& GetInstance(); |
| 85 | tHAL_NFC_ENTRY* GetHalEntryFuncs(); |
| 86 | void DownloadFirmware(); |
Ruchi Kandoi | c0cd1ab | 2017-04-17 17:23:56 -0700 | [diff] [blame] | 87 | void Dump(int fd); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 88 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 89 | private: |
| 90 | NfcAdaptation(); |
| 91 | void signal(); |
| 92 | static NfcAdaptation* mpInstance; |
| 93 | static ThreadMutex sLock; |
| 94 | ThreadCondVar mCondVar; |
| 95 | tHAL_NFC_ENTRY mHalEntryFuncs; // function pointers for HAL entry points |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 96 | static android::sp<android::hardware::nfc::V1_0::INfc> mHal; |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame^] | 97 | static android::sp<android::hardware::nfc::V1_1::INfc> mHal_1_1; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 98 | static android::hardware::nfc::V1_0::INfcClientCallback* mCallback; |
| 99 | static tHAL_NFC_CBACK* mHalCallback; |
| 100 | static tHAL_NFC_DATA_CBACK* mHalDataCallback; |
| 101 | static ThreadCondVar mHalOpenCompletedEvent; |
| 102 | static ThreadCondVar mHalCloseCompletedEvent; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 103 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 104 | static uint32_t NFCA_TASK(uint32_t arg); |
| 105 | static uint32_t Thread(uint32_t arg); |
| 106 | void InitializeHalDeviceContext(); |
| 107 | static void HalDeviceContextCallback(nfc_event_t event, |
| 108 | nfc_status_t event_status); |
| 109 | static void HalDeviceContextDataCallback(uint16_t data_len, uint8_t* p_data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 110 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 111 | static void HalInitialize(); |
| 112 | static void HalTerminate(); |
| 113 | static void HalOpen(tHAL_NFC_CBACK* p_hal_cback, |
| 114 | tHAL_NFC_DATA_CBACK* p_data_cback); |
| 115 | static void HalClose(); |
| 116 | static void HalCoreInitialized(uint16_t data_len, |
| 117 | uint8_t* p_core_init_rsp_params); |
| 118 | static void HalWrite(uint16_t data_len, uint8_t* p_data); |
| 119 | static bool HalPrediscover(); |
| 120 | static void HalControlGranted(); |
| 121 | static void HalPowerCycle(); |
| 122 | static uint8_t HalGetMaxNfcee(); |
| 123 | static void HalDownloadFirmwareCallback(nfc_event_t event, |
| 124 | nfc_status_t event_status); |
| 125 | static void HalDownloadFirmwareDataCallback(uint16_t data_len, |
| 126 | uint8_t* p_data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 127 | }; |