blob: 9382fce737f9d54c1b4c2e208f0d50f2e1544a81 [file] [log] [blame]
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001/******************************************************************************
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 Kandoi3800a822016-12-12 16:49:49 -080020
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080021#include "nfc_hal_api.h"
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080022#include "nfc_target.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080023
Martijn Coenene9e48e52016-09-06 16:05:25 +020024#include <utils/RefBase.h>
25
26namespace android {
27namespace hardware {
28namespace nfc {
29namespace V1_0 {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080030struct INfc;
31struct INfcClientCallback;
32}
Ruchi Kandoi5815b5c2017-12-07 09:30:01 -080033namespace V1_1 {
34struct INfc;
35}
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080036}
37}
38}
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080039
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080040class 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 Projecte9df6ba2012-12-13 14:55:37 -080050};
51
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080052class 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 Projecte9df6ba2012-12-13 14:55:37 -080065};
66
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080067class 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 Projecte9df6ba2012-12-13 14:55:37 -080076};
77
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080078class NfcAdaptation {
79 public:
80 virtual ~NfcAdaptation();
81 void Initialize();
82 void Finalize();
Ruchi Kandoi5815b5c2017-12-07 09:30:01 -080083 void FactoryReset();
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080084 static NfcAdaptation& GetInstance();
85 tHAL_NFC_ENTRY* GetHalEntryFuncs();
86 void DownloadFirmware();
Ruchi Kandoic0cd1ab2017-04-17 17:23:56 -070087 void Dump(int fd);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080088
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080089 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 Kandoi6fca02d2017-01-30 14:28:16 -080096 static android::sp<android::hardware::nfc::V1_0::INfc> mHal;
Ruchi Kandoi5815b5c2017-12-07 09:30:01 -080097 static android::sp<android::hardware::nfc::V1_1::INfc> mHal_1_1;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080098 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 Projecte9df6ba2012-12-13 14:55:37 -0800103
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800104 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 Projecte9df6ba2012-12-13 14:55:37 -0800110
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800111 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 Projecte9df6ba2012-12-13 14:55:37 -0800127};