mbed OS 5 example application using X-NUCLEO-NFC02A1
Dependencies: NDefLib X_NUCLEO_NFC02A1
Fork of HelloWorld_NFC02A1 by
X_NUCLEO_NFC02A1/Interfaces/Nfc_class.h@1:11ae12d41082, 2016-08-30 (annotated)
- Committer:
- rosarium
- Date:
- Tue Aug 30 09:18:50 2016 +0000
- Revision:
- 1:11ae12d41082
NDefLib middle-ware library ported on HelloWorld_NFC02A1. Now NFC02A1 using the same middle-ware library as NFC01A1.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rosarium | 1:11ae12d41082 | 1 | /** |
| rosarium | 1:11ae12d41082 | 2 | ****************************************************************************** |
| rosarium | 1:11ae12d41082 | 3 | * @file Nfc_class.h |
| rosarium | 1:11ae12d41082 | 4 | * @author AMG Central Lab |
| rosarium | 1:11ae12d41082 | 5 | * @version V1.0.0 |
| rosarium | 1:11ae12d41082 | 6 | * @date 30-Aug-2016 |
| rosarium | 1:11ae12d41082 | 7 | * @brief This file contains the abstract class describing the interface of a |
| rosarium | 1:11ae12d41082 | 8 | * nfc component. |
| rosarium | 1:11ae12d41082 | 9 | ****************************************************************************** |
| rosarium | 1:11ae12d41082 | 10 | * @attention |
| rosarium | 1:11ae12d41082 | 11 | * |
| rosarium | 1:11ae12d41082 | 12 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
| rosarium | 1:11ae12d41082 | 13 | * |
| rosarium | 1:11ae12d41082 | 14 | * Redistribution and use in source and binary forms, with or without modification, |
| rosarium | 1:11ae12d41082 | 15 | * are permitted provided that the following conditions are met: |
| rosarium | 1:11ae12d41082 | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
| rosarium | 1:11ae12d41082 | 17 | * this list of conditions and the following disclaimer. |
| rosarium | 1:11ae12d41082 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| rosarium | 1:11ae12d41082 | 19 | * this list of conditions and the following disclaimer in the documentation |
| rosarium | 1:11ae12d41082 | 20 | * and/or other materials provided with the distribution. |
| rosarium | 1:11ae12d41082 | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| rosarium | 1:11ae12d41082 | 22 | * may be used to endorse or promote products derived from this software |
| rosarium | 1:11ae12d41082 | 23 | * without specific prior written permission. |
| rosarium | 1:11ae12d41082 | 24 | * |
| rosarium | 1:11ae12d41082 | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| rosarium | 1:11ae12d41082 | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| rosarium | 1:11ae12d41082 | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| rosarium | 1:11ae12d41082 | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| rosarium | 1:11ae12d41082 | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| rosarium | 1:11ae12d41082 | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| rosarium | 1:11ae12d41082 | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| rosarium | 1:11ae12d41082 | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| rosarium | 1:11ae12d41082 | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| rosarium | 1:11ae12d41082 | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| rosarium | 1:11ae12d41082 | 35 | * |
| rosarium | 1:11ae12d41082 | 36 | ****************************************************************************** |
| rosarium | 1:11ae12d41082 | 37 | */ |
| rosarium | 1:11ae12d41082 | 38 | |
| rosarium | 1:11ae12d41082 | 39 | |
| rosarium | 1:11ae12d41082 | 40 | /* Generated with Stm32CubeTOO -----------------------------------------------*/ |
| rosarium | 1:11ae12d41082 | 41 | |
| rosarium | 1:11ae12d41082 | 42 | /* Define to prevent from recursive inclusion --------------------------------*/ |
| rosarium | 1:11ae12d41082 | 43 | |
| rosarium | 1:11ae12d41082 | 44 | #ifndef __NFC_CLASS_H |
| rosarium | 1:11ae12d41082 | 45 | #define __NFC_CLASS_H |
| rosarium | 1:11ae12d41082 | 46 | |
| rosarium | 1:11ae12d41082 | 47 | |
| rosarium | 1:11ae12d41082 | 48 | /* Includes ------------------------------------------------------------------*/ |
| rosarium | 1:11ae12d41082 | 49 | |
| rosarium | 1:11ae12d41082 | 50 | #include "Component_class.h" |
| rosarium | 1:11ae12d41082 | 51 | #include "../Common/nfc.h" |
| rosarium | 1:11ae12d41082 | 52 | |
| rosarium | 1:11ae12d41082 | 53 | /* Classes ------------------------------------------------------------------*/ |
| rosarium | 1:11ae12d41082 | 54 | |
| rosarium | 1:11ae12d41082 | 55 | /** |
| rosarium | 1:11ae12d41082 | 56 | * An abstract class for Nfc components. |
| rosarium | 1:11ae12d41082 | 57 | * This component has two operation modes, sync or async. |
| rosarium | 1:11ae12d41082 | 58 | * In sync mode each function call returns only after the command has completed. |
| rosarium | 1:11ae12d41082 | 59 | * In async mode each function call returns immediately and the answer will be notified |
| rosarium | 1:11ae12d41082 | 60 | * through a callback. |
| rosarium | 1:11ae12d41082 | 61 | * The default behavior is sync mode. |
| rosarium | 1:11ae12d41082 | 62 | * To enable the async mode ManageI2CGPO(I2C_ANSWER_READY) function must be called. |
| rosarium | 1:11ae12d41082 | 63 | * When the component notifies an interrupt user must call {@link ManageEvent} function. |
| rosarium | 1:11ae12d41082 | 64 | * Note that passing a parameter other than I2C_ANSWER_READY to ManageI2CGPO initialize the component in sync mode. |
| rosarium | 1:11ae12d41082 | 65 | */ |
| rosarium | 1:11ae12d41082 | 66 | class Nfc : public Component |
| rosarium | 1:11ae12d41082 | 67 | { |
| rosarium | 1:11ae12d41082 | 68 | public: |
| rosarium | 1:11ae12d41082 | 69 | |
| rosarium | 1:11ae12d41082 | 70 | /** |
| rosarium | 1:11ae12d41082 | 71 | * Possible password to set. |
| rosarium | 1:11ae12d41082 | 72 | */ |
| rosarium | 1:11ae12d41082 | 73 | typedef enum{ |
| rosarium | 1:11ae12d41082 | 74 | ReadPwd, //!< Password to use before reading the tag |
| rosarium | 1:11ae12d41082 | 75 | WritePwd, //!< Password to use before writing the tag |
| rosarium | 1:11ae12d41082 | 76 | I2CPwd, //!< Root password, used only through nfc |
| rosarium | 1:11ae12d41082 | 77 | }PasswordType_t; |
| rosarium | 1:11ae12d41082 | 78 | |
| rosarium | 1:11ae12d41082 | 79 | /** |
| rosarium | 1:11ae12d41082 | 80 | * Function that will be called when an interrupt is fired, |
| rosarium | 1:11ae12d41082 | 81 | * this function must be set if you want use the component in async mode. |
| rosarium | 1:11ae12d41082 | 82 | */ |
| rosarium | 1:11ae12d41082 | 83 | typedef void(*gpoEventCallback)(void); |
| rosarium | 1:11ae12d41082 | 84 | |
| rosarium | 1:11ae12d41082 | 85 | /** |
| rosarium | 1:11ae12d41082 | 86 | * Object that contains all the callbacks fired by this class, each command has its own callback. |
| rosarium | 1:11ae12d41082 | 87 | * The callback default implementation is an empty function. |
| rosarium | 1:11ae12d41082 | 88 | */ |
| rosarium | 1:11ae12d41082 | 89 | class Callbacks{ |
| rosarium | 1:11ae12d41082 | 90 | public: |
| rosarium | 1:11ae12d41082 | 91 | |
| rosarium | 1:11ae12d41082 | 92 | /** called when GetSession or ForceGetSession completes |
| rosarium | 1:11ae12d41082 | 93 | * @see Nfc#GetSession |
| rosarium | 1:11ae12d41082 | 94 | * @see Nfc#ForceGetSession */ |
| rosarium | 1:11ae12d41082 | 95 | virtual void onSessionOpen(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 96 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 97 | } |
| rosarium | 1:11ae12d41082 | 98 | |
| rosarium | 1:11ae12d41082 | 99 | /** called when Deselect completes |
| rosarium | 1:11ae12d41082 | 100 | * @see Nfc#Deselect */ |
| rosarium | 1:11ae12d41082 | 101 | virtual void onDeselect(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 102 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 103 | } |
| rosarium | 1:11ae12d41082 | 104 | |
| rosarium | 1:11ae12d41082 | 105 | /** called when SelectedApplication completes |
| rosarium | 1:11ae12d41082 | 106 | * @see Nfc#SelectedApplication */ |
| rosarium | 1:11ae12d41082 | 107 | virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 108 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 109 | } |
| rosarium | 1:11ae12d41082 | 110 | |
| rosarium | 1:11ae12d41082 | 111 | /** called when SelectedCCFile completes |
| rosarium | 1:11ae12d41082 | 112 | * @see Nfc#SelectedCCFile */ |
| rosarium | 1:11ae12d41082 | 113 | virtual void onSelectedCCFile(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 114 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 115 | } |
| rosarium | 1:11ae12d41082 | 116 | |
| rosarium | 1:11ae12d41082 | 117 | /** called when SelectedNDEFFile completes |
| rosarium | 1:11ae12d41082 | 118 | * @see Nfc#SelectedNDEFFile */ |
| rosarium | 1:11ae12d41082 | 119 | virtual void onSelectedNDEFFile(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 120 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 121 | } |
| rosarium | 1:11ae12d41082 | 122 | |
| rosarium | 1:11ae12d41082 | 123 | /** called when SelectedSystemFile completes |
| rosarium | 1:11ae12d41082 | 124 | * @see Nfc#SelectedSystemFile */ |
| rosarium | 1:11ae12d41082 | 125 | virtual void onSelectedSystemFile(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 126 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 127 | } |
| rosarium | 1:11ae12d41082 | 128 | |
| rosarium | 1:11ae12d41082 | 129 | /** called when ReadBinary or STReadBinary completes |
| rosarium | 1:11ae12d41082 | 130 | * @see Nfc#ReadBinary |
| rosarium | 1:11ae12d41082 | 131 | * @see Nfc#STReadBinary */ |
| rosarium | 1:11ae12d41082 | 132 | virtual void onReadByte(Nfc *nfc,NFC_StatusTypeDef status, |
| rosarium | 1:11ae12d41082 | 133 | uint16_t offset,uint8_t *readByte, uint16_t nReadByte){ |
| rosarium | 1:11ae12d41082 | 134 | (void)nfc; (void)status;(void)offset; (void)readByte; (void)nReadByte; |
| rosarium | 1:11ae12d41082 | 135 | } |
| rosarium | 1:11ae12d41082 | 136 | |
| rosarium | 1:11ae12d41082 | 137 | /** called when UpdatedBinary completes |
| rosarium | 1:11ae12d41082 | 138 | * @see Nfc#UpdatedBinary */ |
| rosarium | 1:11ae12d41082 | 139 | virtual void onUpdatedBinary(Nfc *nfc,NFC_StatusTypeDef status,uint16_t offset, |
| rosarium | 1:11ae12d41082 | 140 | uint8_t *writeByte,uint16_t nWriteByte){ |
| rosarium | 1:11ae12d41082 | 141 | (void)nfc; (void)status; (void)writeByte; (void)nWriteByte; (void)offset; |
| rosarium | 1:11ae12d41082 | 142 | } |
| rosarium | 1:11ae12d41082 | 143 | |
| rosarium | 1:11ae12d41082 | 144 | /** called when Verify completes |
| rosarium | 1:11ae12d41082 | 145 | * @see Nfc#Verify */ |
| rosarium | 1:11ae12d41082 | 146 | virtual void onVerified(Nfc *nfc,NFC_StatusTypeDef status,PasswordType_t uPwdId, |
| rosarium | 1:11ae12d41082 | 147 | const uint8_t *pwd){ |
| rosarium | 1:11ae12d41082 | 148 | (void)nfc; (void)status;(void)uPwdId;(void)pwd; |
| rosarium | 1:11ae12d41082 | 149 | } |
| rosarium | 1:11ae12d41082 | 150 | |
| rosarium | 1:11ae12d41082 | 151 | /** called when ManageI2CGPO completes |
| rosarium | 1:11ae12d41082 | 152 | * @see Nfc#ManageI2CGPO */ |
| rosarium | 1:11ae12d41082 | 153 | virtual void onManageI2CGPO(Nfc *nfc,NFC_StatusTypeDef status,NFC_GPO_MGMT newStatus){ |
| rosarium | 1:11ae12d41082 | 154 | (void)nfc; (void)status;(void)newStatus; |
| rosarium | 1:11ae12d41082 | 155 | } |
| rosarium | 1:11ae12d41082 | 156 | |
| rosarium | 1:11ae12d41082 | 157 | /** called when ManageRFGPO completes |
| rosarium | 1:11ae12d41082 | 158 | * @see Nfc#ManageRFGPO */ |
| rosarium | 1:11ae12d41082 | 159 | virtual void onManageRFGPO(Nfc *nfc,NFC_StatusTypeDef status,NFC_GPO_MGMT newStatus){ |
| rosarium | 1:11ae12d41082 | 160 | (void)nfc; (void)status;(void)newStatus; |
| rosarium | 1:11ae12d41082 | 161 | } |
| rosarium | 1:11ae12d41082 | 162 | |
| rosarium | 1:11ae12d41082 | 163 | /** called when ChangeReferenceData completes |
| rosarium | 1:11ae12d41082 | 164 | * @see Nfc#ChangeReferenceData */ |
| rosarium | 1:11ae12d41082 | 165 | virtual void onChangeReferenceData(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type, |
| rosarium | 1:11ae12d41082 | 166 | uint8_t *data){ |
| rosarium | 1:11ae12d41082 | 167 | (void)nfc; (void)status;(void)type;(void)data; |
| rosarium | 1:11ae12d41082 | 168 | } |
| rosarium | 1:11ae12d41082 | 169 | |
| rosarium | 1:11ae12d41082 | 170 | /** called when EnableVerificationRequirement completes |
| rosarium | 1:11ae12d41082 | 171 | * @see Nfc#EnableVerificationRequirement */ |
| rosarium | 1:11ae12d41082 | 172 | virtual void onEnableVerificationRequirement(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type){ |
| rosarium | 1:11ae12d41082 | 173 | (void)nfc; (void)status;(void)type; |
| rosarium | 1:11ae12d41082 | 174 | } |
| rosarium | 1:11ae12d41082 | 175 | |
| rosarium | 1:11ae12d41082 | 176 | /** called when DisableVerificationRequirement completes |
| rosarium | 1:11ae12d41082 | 177 | * @see Nfc#DisableVerificationRequirement */ |
| rosarium | 1:11ae12d41082 | 178 | virtual void onDisableVerificationRequirement(Nfc *nfc , NFC_StatusTypeDef status,PasswordType_t type){ |
| rosarium | 1:11ae12d41082 | 179 | (void)nfc; (void)status;(void)type; |
| rosarium | 1:11ae12d41082 | 180 | } |
| rosarium | 1:11ae12d41082 | 181 | |
| rosarium | 1:11ae12d41082 | 182 | /** called when EnablePermanentState completes |
| rosarium | 1:11ae12d41082 | 183 | * @see Nfc#EnablePermanentState */ |
| rosarium | 1:11ae12d41082 | 184 | virtual void onEnablePermanentState(Nfc *nfc, NFC_StatusTypeDef status, PasswordType_t type){ |
| rosarium | 1:11ae12d41082 | 185 | (void)nfc; (void)status;(void)type; |
| rosarium | 1:11ae12d41082 | 186 | } |
| rosarium | 1:11ae12d41082 | 187 | |
| rosarium | 1:11ae12d41082 | 188 | /** called when DisablePermanentState completes |
| rosarium | 1:11ae12d41082 | 189 | * @see Nfc#DisablePermanentState */ |
| rosarium | 1:11ae12d41082 | 190 | virtual void onDisablePermanentState(Nfc *nfc, NFC_StatusTypeDef status, PasswordType_t type){ |
| rosarium | 1:11ae12d41082 | 191 | (void)nfc; (void)status;(void)type; |
| rosarium | 1:11ae12d41082 | 192 | } |
| rosarium | 1:11ae12d41082 | 193 | |
| rosarium | 1:11ae12d41082 | 194 | /** called when ReadId completes |
| rosarium | 1:11ae12d41082 | 195 | * @see Nfc#ReadId */ |
| rosarium | 1:11ae12d41082 | 196 | virtual void onReadId(Nfc *nfc, NFC_StatusTypeDef status, uint8_t *id){ |
| rosarium | 1:11ae12d41082 | 197 | (void)nfc; (void)status;(void)id; |
| rosarium | 1:11ae12d41082 | 198 | } |
| rosarium | 1:11ae12d41082 | 199 | |
| rosarium | 1:11ae12d41082 | 200 | /** called when EnableReadPassword completes |
| rosarium | 1:11ae12d41082 | 201 | * @see Nfc#EnableReadPassword */ |
| rosarium | 1:11ae12d41082 | 202 | virtual void onEnableReadPassword(Nfc *nfc, NFC_StatusTypeDef status,const uint8_t *newPwd){ |
| rosarium | 1:11ae12d41082 | 203 | (void)nfc; (void)status;(void)newPwd; |
| rosarium | 1:11ae12d41082 | 204 | } |
| rosarium | 1:11ae12d41082 | 205 | |
| rosarium | 1:11ae12d41082 | 206 | /** called when EnableWritePassword completes |
| rosarium | 1:11ae12d41082 | 207 | * @see Nfc#EnableWritePassword */ |
| rosarium | 1:11ae12d41082 | 208 | virtual void onEnableWritePassword(Nfc *nfc, NFC_StatusTypeDef status,const uint8_t *newPwd){ |
| rosarium | 1:11ae12d41082 | 209 | (void)nfc; (void)status;(void)newPwd; |
| rosarium | 1:11ae12d41082 | 210 | } |
| rosarium | 1:11ae12d41082 | 211 | |
| rosarium | 1:11ae12d41082 | 212 | /** called when DisableReadPassword completes |
| rosarium | 1:11ae12d41082 | 213 | * @see Nfc#DisableReadPassword */ |
| rosarium | 1:11ae12d41082 | 214 | virtual void onDisableReadPassword(Nfc *nfc, NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 215 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 216 | } |
| rosarium | 1:11ae12d41082 | 217 | |
| rosarium | 1:11ae12d41082 | 218 | /** called when DisableWritePassword completes |
| rosarium | 1:11ae12d41082 | 219 | * @see Nfc#DisableWritePassword */ |
| rosarium | 1:11ae12d41082 | 220 | virtual void onDisableWritePassword(Nfc *nfc, NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 221 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 222 | } |
| rosarium | 1:11ae12d41082 | 223 | |
| rosarium | 1:11ae12d41082 | 224 | /** called when DisableAllPassword completes |
| rosarium | 1:11ae12d41082 | 225 | * @see Nfc#DisableAllPassword */ |
| rosarium | 1:11ae12d41082 | 226 | virtual void onDisableAllPassword(Nfc *nfc, NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 227 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 228 | } |
| rosarium | 1:11ae12d41082 | 229 | |
| rosarium | 1:11ae12d41082 | 230 | |
| rosarium | 1:11ae12d41082 | 231 | /** called when EnableReadOnly completes |
| rosarium | 1:11ae12d41082 | 232 | * @see Nfc#EnableReadOnly */ |
| rosarium | 1:11ae12d41082 | 233 | virtual void onEnableReadOnly(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 234 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 235 | } |
| rosarium | 1:11ae12d41082 | 236 | |
| rosarium | 1:11ae12d41082 | 237 | /** called when EnableWriteOnly completes |
| rosarium | 1:11ae12d41082 | 238 | * @see Nfc#EnableWriteOnly */ |
| rosarium | 1:11ae12d41082 | 239 | virtual void onEnableWriteOnly(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 240 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 241 | } |
| rosarium | 1:11ae12d41082 | 242 | |
| rosarium | 1:11ae12d41082 | 243 | |
| rosarium | 1:11ae12d41082 | 244 | /** called when DisableReadOnly completes |
| rosarium | 1:11ae12d41082 | 245 | * @see Nfc#DisableReadOnly */ |
| rosarium | 1:11ae12d41082 | 246 | virtual void onDisableReadOnly(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 247 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 248 | } |
| rosarium | 1:11ae12d41082 | 249 | |
| rosarium | 1:11ae12d41082 | 250 | /** called when DisableWriteOnly completes |
| rosarium | 1:11ae12d41082 | 251 | * @see Nfc#DisableWriteOnly */ |
| rosarium | 1:11ae12d41082 | 252 | virtual void onDisableWriteOnly(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 253 | (void)nfc; (void)status; |
| rosarium | 1:11ae12d41082 | 254 | } |
| rosarium | 1:11ae12d41082 | 255 | |
| rosarium | 1:11ae12d41082 | 256 | virtual ~Callbacks(){}; |
| rosarium | 1:11ae12d41082 | 257 | }; |
| rosarium | 1:11ae12d41082 | 258 | |
| rosarium | 1:11ae12d41082 | 259 | Nfc():mCallback(&defaultCallback), |
| rosarium | 1:11ae12d41082 | 260 | mComponentCallback(NULL){ } |
| rosarium | 1:11ae12d41082 | 261 | |
| rosarium | 1:11ae12d41082 | 262 | /** |
| rosarium | 1:11ae12d41082 | 263 | * Open a I2C connection with the tag if an RF connection isn't already open. |
| rosarium | 1:11ae12d41082 | 264 | * @return operation status |
| rosarium | 1:11ae12d41082 | 265 | */ |
| rosarium | 1:11ae12d41082 | 266 | virtual NFC_StatusTypeDef GetSession(void) = 0; |
| rosarium | 1:11ae12d41082 | 267 | |
| rosarium | 1:11ae12d41082 | 268 | /** |
| rosarium | 1:11ae12d41082 | 269 | * Force to open an I2C connection , abort the RF connection. |
| rosarium | 1:11ae12d41082 | 270 | * @return NFC_SUCCESS if the session is acquired |
| rosarium | 1:11ae12d41082 | 271 | */ |
| rosarium | 1:11ae12d41082 | 272 | virtual NFC_StatusTypeDef ForceGetSession(void) = 0; |
| rosarium | 1:11ae12d41082 | 273 | |
| rosarium | 1:11ae12d41082 | 274 | /** |
| rosarium | 1:11ae12d41082 | 275 | * Close an I2C connection. |
| rosarium | 1:11ae12d41082 | 276 | * @return NFC_SUCCESS if the session is release |
| rosarium | 1:11ae12d41082 | 277 | */ |
| rosarium | 1:11ae12d41082 | 278 | virtual NFC_StatusTypeDef Deselect(void) = 0; |
| rosarium | 1:11ae12d41082 | 279 | |
| rosarium | 1:11ae12d41082 | 280 | /** |
| rosarium | 1:11ae12d41082 | 281 | * Select the application file. |
| rosarium | 1:11ae12d41082 | 282 | * @return NFC_SUCCESS if the application is selected |
| rosarium | 1:11ae12d41082 | 283 | */ |
| rosarium | 1:11ae12d41082 | 284 | virtual NFC_StatusTypeDef SelectApplication(void) = 0; |
| rosarium | 1:11ae12d41082 | 285 | |
| rosarium | 1:11ae12d41082 | 286 | /** |
| rosarium | 1:11ae12d41082 | 287 | * Select the CC file. |
| rosarium | 1:11ae12d41082 | 288 | * @return NFC_SUCCESS if the CC file is selected. |
| rosarium | 1:11ae12d41082 | 289 | */ |
| rosarium | 1:11ae12d41082 | 290 | virtual NFC_StatusTypeDef SelectCCfile(void) = 0; |
| rosarium | 1:11ae12d41082 | 291 | |
| rosarium | 1:11ae12d41082 | 292 | /** |
| rosarium | 1:11ae12d41082 | 293 | * Select the NDEF file. |
| rosarium | 1:11ae12d41082 | 294 | * @param NDEFfileId File id to open. |
| rosarium | 1:11ae12d41082 | 295 | * @return NFC_SUCCESS if the file is selected |
| rosarium | 1:11ae12d41082 | 296 | */ |
| rosarium | 1:11ae12d41082 | 297 | virtual NFC_StatusTypeDef SelectNDEFfile(uint16_t NDEFfileId) = 0; |
| rosarium | 1:11ae12d41082 | 298 | |
| rosarium | 1:11ae12d41082 | 299 | /** |
| rosarium | 1:11ae12d41082 | 300 | * Select the system file. |
| rosarium | 1:11ae12d41082 | 301 | * @return NFC_SUCCESS if the system file is selected |
| rosarium | 1:11ae12d41082 | 302 | */ |
| rosarium | 1:11ae12d41082 | 303 | virtual NFC_StatusTypeDef SelectSystemfile(void) = 0; |
| rosarium | 1:11ae12d41082 | 304 | |
| rosarium | 1:11ae12d41082 | 305 | /** |
| rosarium | 1:11ae12d41082 | 306 | * Read data from the tag. |
| rosarium | 1:11ae12d41082 | 307 | * @param Offset Read offset. |
| rosarium | 1:11ae12d41082 | 308 | * @param NbByteToRead Number of bytes to read. |
| rosarium | 1:11ae12d41082 | 309 | * @param[out] pBufferRead Buffer to store the read data into. |
| rosarium | 1:11ae12d41082 | 310 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 311 | */ |
| rosarium | 1:11ae12d41082 | 312 | virtual NFC_StatusTypeDef ReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead) = 0; |
| rosarium | 1:11ae12d41082 | 313 | |
| rosarium | 1:11ae12d41082 | 314 | /** |
| rosarium | 1:11ae12d41082 | 315 | * Write data to the tag. |
| rosarium | 1:11ae12d41082 | 316 | * @param Offset Write offset. |
| rosarium | 1:11ae12d41082 | 317 | * @param NbByteToWrite Number of bytes to write. |
| rosarium | 1:11ae12d41082 | 318 | * @param pDataToWrite Buffer to write. |
| rosarium | 1:11ae12d41082 | 319 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 320 | */ |
| rosarium | 1:11ae12d41082 | 321 | virtual NFC_StatusTypeDef UpdateBinary(uint16_t Offset, uint8_t NbByteToWrite, uint8_t *pDataToWrite) = 0; |
| rosarium | 1:11ae12d41082 | 322 | |
| rosarium | 1:11ae12d41082 | 323 | /** |
| rosarium | 1:11ae12d41082 | 324 | * Check that the password is correct. |
| rosarium | 1:11ae12d41082 | 325 | * @param uPwdId Password type. |
| rosarium | 1:11ae12d41082 | 326 | * @param NbPwdByte Password size ( must be 0x10). |
| rosarium | 1:11ae12d41082 | 327 | * @param pPwd Password buffer. |
| rosarium | 1:11ae12d41082 | 328 | * @return NFC_SUCCESS if no errors and write/read permission granted |
| rosarium | 1:11ae12d41082 | 329 | */ |
| rosarium | 1:11ae12d41082 | 330 | virtual NFC_StatusTypeDef Verify(PasswordType_t uPwdId, uint8_t NbPwdByte,const uint8_t *pPwd) = 0; |
| rosarium | 1:11ae12d41082 | 331 | |
| rosarium | 1:11ae12d41082 | 332 | /** |
| rosarium | 1:11ae12d41082 | 333 | * Replace the read or write password. |
| rosarium | 1:11ae12d41082 | 334 | * @param uPwdId Password to change. |
| rosarium | 1:11ae12d41082 | 335 | * @param pPwd New password. |
| rosarium | 1:11ae12d41082 | 336 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 337 | */ |
| rosarium | 1:11ae12d41082 | 338 | virtual NFC_StatusTypeDef ChangeReferenceData(PasswordType_t uPwdId,const uint8_t *pPwd) = 0; |
| rosarium | 1:11ae12d41082 | 339 | |
| rosarium | 1:11ae12d41082 | 340 | /** |
| rosarium | 1:11ae12d41082 | 341 | * Activate NDEF file password protection. |
| rosarium | 1:11ae12d41082 | 342 | * When this command is successful, read or write access to the NDEF file is protected by a 128-bit password. |
| rosarium | 1:11ae12d41082 | 343 | * @param uReadOrWrite Read or write password. |
| rosarium | 1:11ae12d41082 | 344 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 345 | */ |
| rosarium | 1:11ae12d41082 | 346 | virtual NFC_StatusTypeDef EnableVerificationRequirement(PasswordType_t uReadOrWrite) = 0; |
| rosarium | 1:11ae12d41082 | 347 | |
| rosarium | 1:11ae12d41082 | 348 | /** |
| rosarium | 1:11ae12d41082 | 349 | * Deactivate NDEF file password protection. |
| rosarium | 1:11ae12d41082 | 350 | * When this command is successful, read or write access to the NDEF file is granted. |
| rosarium | 1:11ae12d41082 | 351 | * with no security enforcement. |
| rosarium | 1:11ae12d41082 | 352 | * @param uReadOrWrite Read or write password. |
| rosarium | 1:11ae12d41082 | 353 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 354 | */ |
| rosarium | 1:11ae12d41082 | 355 | virtual NFC_StatusTypeDef DisableVerificationRequirement(PasswordType_t uReadOrWrite) = 0; |
| rosarium | 1:11ae12d41082 | 356 | |
| rosarium | 1:11ae12d41082 | 357 | /** |
| rosarium | 1:11ae12d41082 | 358 | * Same as {@link NFC#ReadBinary}, however permitting to read more bytes than available. |
| rosarium | 1:11ae12d41082 | 359 | * @param Offset read offset. |
| rosarium | 1:11ae12d41082 | 360 | * @param NbByteToRead Number of bytes to read. |
| rosarium | 1:11ae12d41082 | 361 | * @param[out] pBufferRead Buffer to store the read data into. |
| rosarium | 1:11ae12d41082 | 362 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 363 | */ |
| rosarium | 1:11ae12d41082 | 364 | virtual NFC_StatusTypeDef STReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead) = 0; |
| rosarium | 1:11ae12d41082 | 365 | |
| rosarium | 1:11ae12d41082 | 366 | /** |
| rosarium | 1:11ae12d41082 | 367 | * Set the tag as read/write only, stored in the eeprom. |
| rosarium | 1:11ae12d41082 | 368 | * @param uReadOrWrite ReadPwd if write only, WritePwd if read only. |
| rosarium | 1:11ae12d41082 | 369 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 370 | */ |
| rosarium | 1:11ae12d41082 | 371 | virtual NFC_StatusTypeDef EnablePermanentState(PasswordType_t uReadOrWrite) = 0; |
| rosarium | 1:11ae12d41082 | 372 | |
| rosarium | 1:11ae12d41082 | 373 | /** |
| rosarium | 1:11ae12d41082 | 374 | * Unset the tag as read/write only, stored in the eeprom. |
| rosarium | 1:11ae12d41082 | 375 | * @param uReadOrWrite ReadPwd if write only, WritePwd if read only. |
| rosarium | 1:11ae12d41082 | 376 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 377 | * @par Caller must have I2Csuper user permissions to call this function. |
| rosarium | 1:11ae12d41082 | 378 | */ |
| rosarium | 1:11ae12d41082 | 379 | virtual NFC_StatusTypeDef DisablePermanentState(PasswordType_t uReadOrWrite) = 0; |
| rosarium | 1:11ae12d41082 | 380 | |
| rosarium | 1:11ae12d41082 | 381 | /** |
| rosarium | 1:11ae12d41082 | 382 | * Set the gpo output pin. |
| rosarium | 1:11ae12d41082 | 383 | * @param uSetOrReset New pin status. |
| rosarium | 1:11ae12d41082 | 384 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 385 | */ |
| rosarium | 1:11ae12d41082 | 386 | virtual NFC_StatusTypeDef StateControl(uint8_t uSetOrReset) = 0; |
| rosarium | 1:11ae12d41082 | 387 | |
| rosarium | 1:11ae12d41082 | 388 | /** |
| rosarium | 1:11ae12d41082 | 389 | * @brief This function configures GPO for I2C session. |
| rosarium | 1:11ae12d41082 | 390 | * @param GPO_I2Cconfig GPO configuration to set. |
| rosarium | 1:11ae12d41082 | 391 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 392 | * @par if the configuration is I2C_ANSWER_READY, the component will start to work |
| rosarium | 1:11ae12d41082 | 393 | * in async mode. |
| rosarium | 1:11ae12d41082 | 394 | */ |
| rosarium | 1:11ae12d41082 | 395 | virtual NFC_StatusTypeDef ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig) = 0; |
| rosarium | 1:11ae12d41082 | 396 | |
| rosarium | 1:11ae12d41082 | 397 | /** |
| rosarium | 1:11ae12d41082 | 398 | * @brief This function configures GPO for RF session. |
| rosarium | 1:11ae12d41082 | 399 | * @param GPO_RFconfig GPO configuration to set. |
| rosarium | 1:11ae12d41082 | 400 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 401 | */ |
| rosarium | 1:11ae12d41082 | 402 | virtual NFC_StatusTypeDef ManageRFGPO(uint8_t GPO_RFconfig) = 0; |
| rosarium | 1:11ae12d41082 | 403 | |
| rosarium | 1:11ae12d41082 | 404 | /** |
| rosarium | 1:11ae12d41082 | 405 | * @brief This function enables or disables the RF communication. |
| rosarium | 1:11ae12d41082 | 406 | * @param OnOffChoice GPO configuration to set. |
| rosarium | 1:11ae12d41082 | 407 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 408 | */ |
| rosarium | 1:11ae12d41082 | 409 | virtual NFC_StatusTypeDef RFConfig(uint8_t OnOffChoice) = 0; |
| rosarium | 1:11ae12d41082 | 410 | |
| rosarium | 1:11ae12d41082 | 411 | /** |
| rosarium | 1:11ae12d41082 | 412 | * Generates a negative pulse on the GPO pin. |
| rosarium | 1:11ae12d41082 | 413 | * Pulse starts immediately after the command is issued and ends at the end of the RF response. |
| rosarium | 1:11ae12d41082 | 414 | * @return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 415 | */ |
| rosarium | 1:11ae12d41082 | 416 | virtual NFC_StatusTypeDef SendInterrupt(void)=0; |
| rosarium | 1:11ae12d41082 | 417 | |
| rosarium | 1:11ae12d41082 | 418 | /** |
| rosarium | 1:11ae12d41082 | 419 | * Change the function to call when a command ends. |
| rosarium | 1:11ae12d41082 | 420 | * @param commandCallback Object containing the callback, if NULL it will use empty callback |
| rosarium | 1:11ae12d41082 | 421 | */ |
| rosarium | 1:11ae12d41082 | 422 | void SetCallback(Callbacks *commandCallback){ |
| rosarium | 1:11ae12d41082 | 423 | if(commandCallback!=NULL) |
| rosarium | 1:11ae12d41082 | 424 | mCallback = commandCallback; |
| rosarium | 1:11ae12d41082 | 425 | else |
| rosarium | 1:11ae12d41082 | 426 | mCallback = &defaultCallback; |
| rosarium | 1:11ae12d41082 | 427 | } |
| rosarium | 1:11ae12d41082 | 428 | |
| rosarium | 1:11ae12d41082 | 429 | /** |
| rosarium | 1:11ae12d41082 | 430 | * Function to call when the component fire an interrupt. |
| rosarium | 1:11ae12d41082 | 431 | * @return last operation status |
| rosarium | 1:11ae12d41082 | 432 | */ |
| rosarium | 1:11ae12d41082 | 433 | virtual NFC_StatusTypeDef ManageEvent()=0; |
| rosarium | 1:11ae12d41082 | 434 | |
| rosarium | 1:11ae12d41082 | 435 | |
| rosarium | 1:11ae12d41082 | 436 | ///////////////////////HIGH LEVEL / UTILITY FUNCTIONS //////////////////////////////////// |
| rosarium | 1:11ae12d41082 | 437 | |
| rosarium | 1:11ae12d41082 | 438 | /** |
| rosarium | 1:11ae12d41082 | 439 | * Enable the request of a password before reading the tag. |
| rosarium | 1:11ae12d41082 | 440 | * @param pCurrentWritePassword Current password |
| rosarium | 1:11ae12d41082 | 441 | * @param pNewPassword Password to request before reading the tag. |
| rosarium | 1:11ae12d41082 | 442 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 443 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 444 | */ |
| rosarium | 1:11ae12d41082 | 445 | NFC_StatusTypeDef EnableReadPassword(const uint8_t* pCurrentWritePassword, |
| rosarium | 1:11ae12d41082 | 446 | const uint8_t* pNewPassword) { |
| rosarium | 1:11ae12d41082 | 447 | |
| rosarium | 1:11ae12d41082 | 448 | //enable the callback for change the gpo |
| rosarium | 1:11ae12d41082 | 449 | mComponentCallback = &mChangePasswordRequestStatusCallback; |
| rosarium | 1:11ae12d41082 | 450 | mChangePasswordRequestStatusCallback.setTask(ReadPwd,pNewPassword); |
| rosarium | 1:11ae12d41082 | 451 | |
| rosarium | 1:11ae12d41082 | 452 | return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword); |
| rosarium | 1:11ae12d41082 | 453 | } |
| rosarium | 1:11ae12d41082 | 454 | |
| rosarium | 1:11ae12d41082 | 455 | /** |
| rosarium | 1:11ae12d41082 | 456 | * Disable the request of a password before reading the tag. |
| rosarium | 1:11ae12d41082 | 457 | * @param pCurrentWritePassword Current password |
| rosarium | 1:11ae12d41082 | 458 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 459 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 460 | */ |
| rosarium | 1:11ae12d41082 | 461 | NFC_StatusTypeDef DisableReadPassword(const uint8_t* pCurrentWritePassword) { |
| rosarium | 1:11ae12d41082 | 462 | mComponentCallback = &mChangePasswordRequestStatusCallback; |
| rosarium | 1:11ae12d41082 | 463 | mChangePasswordRequestStatusCallback.setTask(ReadPwd,NULL); |
| rosarium | 1:11ae12d41082 | 464 | |
| rosarium | 1:11ae12d41082 | 465 | return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword); |
| rosarium | 1:11ae12d41082 | 466 | } |
| rosarium | 1:11ae12d41082 | 467 | |
| rosarium | 1:11ae12d41082 | 468 | /** |
| rosarium | 1:11ae12d41082 | 469 | * Enable the request of a password before writing to the tag. |
| rosarium | 1:11ae12d41082 | 470 | * @param pCurrentWritePassword Current password |
| rosarium | 1:11ae12d41082 | 471 | * @param pNewPassword Password to request before reading the tag. |
| rosarium | 1:11ae12d41082 | 472 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 473 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 474 | */ |
| rosarium | 1:11ae12d41082 | 475 | NFC_StatusTypeDef EnableWritePassword(const uint8_t* pCurrentWritePassword, |
| rosarium | 1:11ae12d41082 | 476 | uint8_t* pNewPassword) { |
| rosarium | 1:11ae12d41082 | 477 | //enable the callback for change the gpo |
| rosarium | 1:11ae12d41082 | 478 | mComponentCallback = &mChangePasswordRequestStatusCallback; |
| rosarium | 1:11ae12d41082 | 479 | mChangePasswordRequestStatusCallback.setTask(WritePwd,pNewPassword); |
| rosarium | 1:11ae12d41082 | 480 | |
| rosarium | 1:11ae12d41082 | 481 | return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword); |
| rosarium | 1:11ae12d41082 | 482 | } |
| rosarium | 1:11ae12d41082 | 483 | |
| rosarium | 1:11ae12d41082 | 484 | /** |
| rosarium | 1:11ae12d41082 | 485 | * Disable the request of a password before writing the tag. |
| rosarium | 1:11ae12d41082 | 486 | * @param pCurrentWritePassword Current password. |
| rosarium | 1:11ae12d41082 | 487 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 488 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 489 | */ |
| rosarium | 1:11ae12d41082 | 490 | NFC_StatusTypeDef DisableWritePassword(const uint8_t* pCurrentWritePassword) { |
| rosarium | 1:11ae12d41082 | 491 | mComponentCallback = &mChangePasswordRequestStatusCallback; |
| rosarium | 1:11ae12d41082 | 492 | mChangePasswordRequestStatusCallback.setTask(WritePwd,NULL); |
| rosarium | 1:11ae12d41082 | 493 | |
| rosarium | 1:11ae12d41082 | 494 | return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword); |
| rosarium | 1:11ae12d41082 | 495 | } |
| rosarium | 1:11ae12d41082 | 496 | |
| rosarium | 1:11ae12d41082 | 497 | /** |
| rosarium | 1:11ae12d41082 | 498 | * @brief This function disables both read and write passwords. |
| rosarium | 1:11ae12d41082 | 499 | * @param pSuperUserPassword I2C super user password. |
| rosarium | 1:11ae12d41082 | 500 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 501 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 502 | */ |
| rosarium | 1:11ae12d41082 | 503 | NFC_StatusTypeDef DisableAllPassword(const uint8_t* pSuperUserPassword){ |
| rosarium | 1:11ae12d41082 | 504 | mComponentCallback = &mRemoveAllPasswordCallback; |
| rosarium | 1:11ae12d41082 | 505 | return Verify(Nfc::I2CPwd, 0x10, pSuperUserPassword); |
| rosarium | 1:11ae12d41082 | 506 | } |
| rosarium | 1:11ae12d41082 | 507 | |
| rosarium | 1:11ae12d41082 | 508 | /** |
| rosarium | 1:11ae12d41082 | 509 | * @brief This function enables read only mode. |
| rosarium | 1:11ae12d41082 | 510 | * @param pCurrentWritePassword Write password is needed to enable read only mode. |
| rosarium | 1:11ae12d41082 | 511 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 512 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 513 | */ |
| rosarium | 1:11ae12d41082 | 514 | NFC_StatusTypeDef EnableReadOnly(const uint8_t* pCurrentWritePassword){ |
| rosarium | 1:11ae12d41082 | 515 | |
| rosarium | 1:11ae12d41082 | 516 | mComponentCallback = &mChangeAccessStateCallback; |
| rosarium | 1:11ae12d41082 | 517 | //disable write = read only |
| rosarium | 1:11ae12d41082 | 518 | mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::WRITE,false); |
| rosarium | 1:11ae12d41082 | 519 | |
| rosarium | 1:11ae12d41082 | 520 | return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword); |
| rosarium | 1:11ae12d41082 | 521 | } |
| rosarium | 1:11ae12d41082 | 522 | |
| rosarium | 1:11ae12d41082 | 523 | /** |
| rosarium | 1:11ae12d41082 | 524 | * @brief This function disables read only mode. |
| rosarium | 1:11ae12d41082 | 525 | * @param pCurrentWritePassword Write password is needed to disable read only mode. |
| rosarium | 1:11ae12d41082 | 526 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 527 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 528 | */ |
| rosarium | 1:11ae12d41082 | 529 | NFC_StatusTypeDef DisableReadOnly(const uint8_t* pCurrentWritePassword) { |
| rosarium | 1:11ae12d41082 | 530 | mComponentCallback = &mChangeAccessStateCallback; |
| rosarium | 1:11ae12d41082 | 531 | mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::WRITE,true); |
| rosarium | 1:11ae12d41082 | 532 | return Verify(Nfc::I2CPwd, 0x10,pCurrentWritePassword); |
| rosarium | 1:11ae12d41082 | 533 | } |
| rosarium | 1:11ae12d41082 | 534 | |
| rosarium | 1:11ae12d41082 | 535 | |
| rosarium | 1:11ae12d41082 | 536 | /** |
| rosarium | 1:11ae12d41082 | 537 | * @brief This function enables write only mode. |
| rosarium | 1:11ae12d41082 | 538 | * @param pCurrentWritePassword Write password is needed to enable write only mode. |
| rosarium | 1:11ae12d41082 | 539 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 540 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 541 | */ |
| rosarium | 1:11ae12d41082 | 542 | NFC_StatusTypeDef EnableWriteOnly(const uint8_t* pCurrentWritePassword) { |
| rosarium | 1:11ae12d41082 | 543 | |
| rosarium | 1:11ae12d41082 | 544 | mComponentCallback = &mChangeAccessStateCallback; |
| rosarium | 1:11ae12d41082 | 545 | //disable read = enable write only |
| rosarium | 1:11ae12d41082 | 546 | mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::READ,false); |
| rosarium | 1:11ae12d41082 | 547 | |
| rosarium | 1:11ae12d41082 | 548 | return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword); |
| rosarium | 1:11ae12d41082 | 549 | |
| rosarium | 1:11ae12d41082 | 550 | } |
| rosarium | 1:11ae12d41082 | 551 | |
| rosarium | 1:11ae12d41082 | 552 | /** |
| rosarium | 1:11ae12d41082 | 553 | * @brief This function disables write only mode. |
| rosarium | 1:11ae12d41082 | 554 | * @param pCurrentWritePassword Write password is needed to disable write only mode. |
| rosarium | 1:11ae12d41082 | 555 | * @return return NFC_SUCCESS if no errors |
| rosarium | 1:11ae12d41082 | 556 | * @par The password must have a length of 16 chars. |
| rosarium | 1:11ae12d41082 | 557 | */ |
| rosarium | 1:11ae12d41082 | 558 | NFC_StatusTypeDef DisableWriteOnly(const uint8_t* pCurrentWritePassword) { |
| rosarium | 1:11ae12d41082 | 559 | mComponentCallback = &mChangeAccessStateCallback; |
| rosarium | 1:11ae12d41082 | 560 | mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::READ,true); |
| rosarium | 1:11ae12d41082 | 561 | return Verify(Nfc::I2CPwd, 0x10, pCurrentWritePassword); |
| rosarium | 1:11ae12d41082 | 562 | } |
| rosarium | 1:11ae12d41082 | 563 | |
| rosarium | 1:11ae12d41082 | 564 | virtual ~Nfc(){}; |
| rosarium | 1:11ae12d41082 | 565 | |
| rosarium | 1:11ae12d41082 | 566 | protected: |
| rosarium | 1:11ae12d41082 | 567 | /** object containing the callbacks to use*/ |
| rosarium | 1:11ae12d41082 | 568 | Callbacks *mCallback; |
| rosarium | 1:11ae12d41082 | 569 | |
| rosarium | 1:11ae12d41082 | 570 | /** |
| rosarium | 1:11ae12d41082 | 571 | * Object with private callbacks used to hide high level commands each |
| rosarium | 1:11ae12d41082 | 572 | * calling multiple low level commands. This callbacks object has |
| rosarium | 1:11ae12d41082 | 573 | * higher priority comparing to the user callbacks. |
| rosarium | 1:11ae12d41082 | 574 | */ |
| rosarium | 1:11ae12d41082 | 575 | Nfc::Callbacks *mComponentCallback; |
| rosarium | 1:11ae12d41082 | 576 | |
| rosarium | 1:11ae12d41082 | 577 | /** |
| rosarium | 1:11ae12d41082 | 578 | * get the callback object to use |
| rosarium | 1:11ae12d41082 | 579 | * @return callback object to use |
| rosarium | 1:11ae12d41082 | 580 | */ |
| rosarium | 1:11ae12d41082 | 581 | Nfc::Callbacks * getCallback(){ |
| rosarium | 1:11ae12d41082 | 582 | if(mComponentCallback!=NULL) |
| rosarium | 1:11ae12d41082 | 583 | return mComponentCallback; |
| rosarium | 1:11ae12d41082 | 584 | return mCallback; |
| rosarium | 1:11ae12d41082 | 585 | }//getCallback |
| rosarium | 1:11ae12d41082 | 586 | |
| rosarium | 1:11ae12d41082 | 587 | private: |
| rosarium | 1:11ae12d41082 | 588 | /** object containing empty callback to use in the default case*/ |
| rosarium | 1:11ae12d41082 | 589 | Callbacks defaultCallback; |
| rosarium | 1:11ae12d41082 | 590 | |
| rosarium | 1:11ae12d41082 | 591 | |
| rosarium | 1:11ae12d41082 | 592 | /** |
| rosarium | 1:11ae12d41082 | 593 | * This class permits to enable/disable the password request to read/write into the tag |
| rosarium | 1:11ae12d41082 | 594 | * This class is equivalent to calling the methods: |
| rosarium | 1:11ae12d41082 | 595 | * To enable the request: |
| rosarium | 1:11ae12d41082 | 596 | * <ul> |
| rosarium | 1:11ae12d41082 | 597 | * <li> Verify </li> |
| rosarium | 1:11ae12d41082 | 598 | * <li> ChangeReferenceData </li> |
| rosarium | 1:11ae12d41082 | 599 | * <li> EnablePermanentState </li> |
| rosarium | 1:11ae12d41082 | 600 | * </ul> |
| rosarium | 1:11ae12d41082 | 601 | * To disable the request: |
| rosarium | 1:11ae12d41082 | 602 | * <ul> |
| rosarium | 1:11ae12d41082 | 603 | * <li> Verify </li> |
| rosarium | 1:11ae12d41082 | 604 | * <li> DisableVerificationRequirement </li> |
| rosarium | 1:11ae12d41082 | 605 | * </ul> |
| rosarium | 1:11ae12d41082 | 606 | */ |
| rosarium | 1:11ae12d41082 | 607 | class ChangePasswordRequestStatusCallback : public Nfc::Callbacks{ |
| rosarium | 1:11ae12d41082 | 608 | |
| rosarium | 1:11ae12d41082 | 609 | public: |
| rosarium | 1:11ae12d41082 | 610 | |
| rosarium | 1:11ae12d41082 | 611 | /** |
| rosarium | 1:11ae12d41082 | 612 | * Build the chain of callbacks. |
| rosarium | 1:11ae12d41082 | 613 | */ |
| rosarium | 1:11ae12d41082 | 614 | ChangePasswordRequestStatusCallback(): |
| rosarium | 1:11ae12d41082 | 615 | mNewPwd(NULL),mType(I2CPwd),mEnable(false){} |
| rosarium | 1:11ae12d41082 | 616 | |
| rosarium | 1:11ae12d41082 | 617 | /** |
| rosarium | 1:11ae12d41082 | 618 | * Set the password to enable/disable. |
| rosarium | 1:11ae12d41082 | 619 | * @param type Type of password to enable/disable. |
| rosarium | 1:11ae12d41082 | 620 | * @param newPwd Array of 16bytes with the new password, if null the request will be disabled. |
| rosarium | 1:11ae12d41082 | 621 | */ |
| rosarium | 1:11ae12d41082 | 622 | void setTask(PasswordType_t type, const uint8_t *newPwd){ |
| rosarium | 1:11ae12d41082 | 623 | mNewPwd=newPwd; |
| rosarium | 1:11ae12d41082 | 624 | mType=type; |
| rosarium | 1:11ae12d41082 | 625 | mEnable=newPwd!=NULL; |
| rosarium | 1:11ae12d41082 | 626 | }//setTask |
| rosarium | 1:11ae12d41082 | 627 | |
| rosarium | 1:11ae12d41082 | 628 | virtual void onVerified(Nfc *nfc, NFC_StatusTypeDef status,PasswordType_t , |
| rosarium | 1:11ae12d41082 | 629 | const uint8_t *){ |
| rosarium | 1:11ae12d41082 | 630 | if(status!=NFC_SUCCESS) |
| rosarium | 1:11ae12d41082 | 631 | return onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 632 | if(mEnable) |
| rosarium | 1:11ae12d41082 | 633 | nfc->ChangeReferenceData(mType,mNewPwd); |
| rosarium | 1:11ae12d41082 | 634 | else |
| rosarium | 1:11ae12d41082 | 635 | nfc->DisableVerificationRequirement(mType); |
| rosarium | 1:11ae12d41082 | 636 | } |
| rosarium | 1:11ae12d41082 | 637 | |
| rosarium | 1:11ae12d41082 | 638 | virtual void onDisableVerificationRequirement(Nfc *nfc, |
| rosarium | 1:11ae12d41082 | 639 | NFC_StatusTypeDef status, PasswordType_t ){ |
| rosarium | 1:11ae12d41082 | 640 | onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 641 | } |
| rosarium | 1:11ae12d41082 | 642 | |
| rosarium | 1:11ae12d41082 | 643 | virtual void onChangeReferenceData(Nfc *nfc, NFC_StatusTypeDef status, |
| rosarium | 1:11ae12d41082 | 644 | PasswordType_t type, |
| rosarium | 1:11ae12d41082 | 645 | uint8_t *){ |
| rosarium | 1:11ae12d41082 | 646 | if(status==NFC_SUCCESS) |
| rosarium | 1:11ae12d41082 | 647 | nfc->EnablePermanentState(type); |
| rosarium | 1:11ae12d41082 | 648 | else |
| rosarium | 1:11ae12d41082 | 649 | onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 650 | } |
| rosarium | 1:11ae12d41082 | 651 | |
| rosarium | 1:11ae12d41082 | 652 | virtual void onEnablePermanentState(Nfc *nfc, NFC_StatusTypeDef status, |
| rosarium | 1:11ae12d41082 | 653 | PasswordType_t ){ |
| rosarium | 1:11ae12d41082 | 654 | onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 655 | } |
| rosarium | 1:11ae12d41082 | 656 | |
| rosarium | 1:11ae12d41082 | 657 | |
| rosarium | 1:11ae12d41082 | 658 | private: |
| rosarium | 1:11ae12d41082 | 659 | |
| rosarium | 1:11ae12d41082 | 660 | /** |
| rosarium | 1:11ae12d41082 | 661 | * Remove the private callbacks and call the user callback. |
| rosarium | 1:11ae12d41082 | 662 | * @param nfc Object triggering the command. |
| rosarium | 1:11ae12d41082 | 663 | * @param status Command status. |
| rosarium | 1:11ae12d41082 | 664 | */ |
| rosarium | 1:11ae12d41082 | 665 | void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 666 | nfc->mComponentCallback=NULL; |
| rosarium | 1:11ae12d41082 | 667 | |
| rosarium | 1:11ae12d41082 | 668 | if(mEnable){ |
| rosarium | 1:11ae12d41082 | 669 | if(mType==ReadPwd){ |
| rosarium | 1:11ae12d41082 | 670 | nfc->getCallback()->onEnableReadPassword(nfc,status,mNewPwd); |
| rosarium | 1:11ae12d41082 | 671 | }else |
| rosarium | 1:11ae12d41082 | 672 | nfc->getCallback()->onEnableWritePassword(nfc,status,mNewPwd); |
| rosarium | 1:11ae12d41082 | 673 | }else{ |
| rosarium | 1:11ae12d41082 | 674 | if(mType==ReadPwd){ |
| rosarium | 1:11ae12d41082 | 675 | nfc->getCallback()->onDisableReadPassword(nfc,status); |
| rosarium | 1:11ae12d41082 | 676 | }else |
| rosarium | 1:11ae12d41082 | 677 | nfc->getCallback()->onDisableWritePassword(nfc,status); |
| rosarium | 1:11ae12d41082 | 678 | }//if-else enable |
| rosarium | 1:11ae12d41082 | 679 | }//onFinish |
| rosarium | 1:11ae12d41082 | 680 | |
| rosarium | 1:11ae12d41082 | 681 | const uint8_t *mNewPwd; |
| rosarium | 1:11ae12d41082 | 682 | Nfc::PasswordType_t mType; |
| rosarium | 1:11ae12d41082 | 683 | bool mEnable; |
| rosarium | 1:11ae12d41082 | 684 | |
| rosarium | 1:11ae12d41082 | 685 | }; |
| rosarium | 1:11ae12d41082 | 686 | |
| rosarium | 1:11ae12d41082 | 687 | |
| rosarium | 1:11ae12d41082 | 688 | /** |
| rosarium | 1:11ae12d41082 | 689 | * Object containing the callback chain needed to change the password request |
| rosarium | 1:11ae12d41082 | 690 | */ |
| rosarium | 1:11ae12d41082 | 691 | ChangePasswordRequestStatusCallback mChangePasswordRequestStatusCallback; |
| rosarium | 1:11ae12d41082 | 692 | friend class ChangePasswordRequestStatusCallback; |
| rosarium | 1:11ae12d41082 | 693 | |
| rosarium | 1:11ae12d41082 | 694 | /** |
| rosarium | 1:11ae12d41082 | 695 | * This class permits to disable all the password requests to read/write into the tag |
| rosarium | 1:11ae12d41082 | 696 | * This class is equivalent to calling the methods: |
| rosarium | 1:11ae12d41082 | 697 | * <ul> |
| rosarium | 1:11ae12d41082 | 698 | * <li> Verify(i2c) </li> |
| rosarium | 1:11ae12d41082 | 699 | * <li> DisablePermanentState(Read) </li> |
| rosarium | 1:11ae12d41082 | 700 | * <li> DisablePermanentState(write) </li> |
| rosarium | 1:11ae12d41082 | 701 | * <li> DisableVerificationRequirement(Read) </li> |
| rosarium | 1:11ae12d41082 | 702 | * <li> DisableVerificationRequirement(write) </li> |
| rosarium | 1:11ae12d41082 | 703 | * <li> ChangeReferenceData(Read) </li> |
| rosarium | 1:11ae12d41082 | 704 | * <li> ChangeReferenceData(write) </li> |
| rosarium | 1:11ae12d41082 | 705 | * </ul> |
| rosarium | 1:11ae12d41082 | 706 | */ |
| rosarium | 1:11ae12d41082 | 707 | class RemoveAllPasswordCallback : public Nfc::Callbacks{ |
| rosarium | 1:11ae12d41082 | 708 | |
| rosarium | 1:11ae12d41082 | 709 | /** |
| rosarium | 1:11ae12d41082 | 710 | * Store the default password used for open a super user session |
| rosarium | 1:11ae12d41082 | 711 | * it will be set as default read/write password |
| rosarium | 1:11ae12d41082 | 712 | */ |
| rosarium | 1:11ae12d41082 | 713 | const uint8_t *mI2CPwd; |
| rosarium | 1:11ae12d41082 | 714 | |
| rosarium | 1:11ae12d41082 | 715 | public: |
| rosarium | 1:11ae12d41082 | 716 | |
| rosarium | 1:11ae12d41082 | 717 | /** |
| rosarium | 1:11ae12d41082 | 718 | * Build the chain of callbacks. |
| rosarium | 1:11ae12d41082 | 719 | */ |
| rosarium | 1:11ae12d41082 | 720 | RemoveAllPasswordCallback():mI2CPwd(NULL){} |
| rosarium | 1:11ae12d41082 | 721 | |
| rosarium | 1:11ae12d41082 | 722 | virtual void onVerified(Nfc *nfc,NFC_StatusTypeDef status, |
| rosarium | 1:11ae12d41082 | 723 | PasswordType_t,const uint8_t* data){ |
| rosarium | 1:11ae12d41082 | 724 | if(status!=NFC_SUCCESS) |
| rosarium | 1:11ae12d41082 | 725 | return onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 726 | mI2CPwd = data; |
| rosarium | 1:11ae12d41082 | 727 | nfc->DisablePermanentState(ReadPwd); |
| rosarium | 1:11ae12d41082 | 728 | } |
| rosarium | 1:11ae12d41082 | 729 | |
| rosarium | 1:11ae12d41082 | 730 | virtual void onDisablePermanentState(Nfc *nfc , NFC_StatusTypeDef status, |
| rosarium | 1:11ae12d41082 | 731 | PasswordType_t type){ |
| rosarium | 1:11ae12d41082 | 732 | if(status!=NFC_SUCCESS) |
| rosarium | 1:11ae12d41082 | 733 | return onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 734 | if(type==ReadPwd) |
| rosarium | 1:11ae12d41082 | 735 | nfc->DisablePermanentState(WritePwd); |
| rosarium | 1:11ae12d41082 | 736 | else |
| rosarium | 1:11ae12d41082 | 737 | nfc->DisableVerificationRequirement(ReadPwd); |
| rosarium | 1:11ae12d41082 | 738 | } |
| rosarium | 1:11ae12d41082 | 739 | |
| rosarium | 1:11ae12d41082 | 740 | virtual void onDisableVerificationRequirement(Nfc *nfc , |
| rosarium | 1:11ae12d41082 | 741 | NFC_StatusTypeDef status,PasswordType_t type){ |
| rosarium | 1:11ae12d41082 | 742 | if(status!=NFC_SUCCESS) |
| rosarium | 1:11ae12d41082 | 743 | return onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 744 | if(type==ReadPwd) |
| rosarium | 1:11ae12d41082 | 745 | nfc->DisableVerificationRequirement(WritePwd); |
| rosarium | 1:11ae12d41082 | 746 | else |
| rosarium | 1:11ae12d41082 | 747 | nfc->ChangeReferenceData(ReadPwd,mI2CPwd); |
| rosarium | 1:11ae12d41082 | 748 | } |
| rosarium | 1:11ae12d41082 | 749 | |
| rosarium | 1:11ae12d41082 | 750 | virtual void onChangeReferenceData(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type, |
| rosarium | 1:11ae12d41082 | 751 | uint8_t *data){ |
| rosarium | 1:11ae12d41082 | 752 | if(status!=NFC_SUCCESS) |
| rosarium | 1:11ae12d41082 | 753 | return onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 754 | if(type==ReadPwd) |
| rosarium | 1:11ae12d41082 | 755 | nfc->ChangeReferenceData(WritePwd,data); |
| rosarium | 1:11ae12d41082 | 756 | else |
| rosarium | 1:11ae12d41082 | 757 | onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 758 | } |
| rosarium | 1:11ae12d41082 | 759 | |
| rosarium | 1:11ae12d41082 | 760 | private: |
| rosarium | 1:11ae12d41082 | 761 | |
| rosarium | 1:11ae12d41082 | 762 | /** |
| rosarium | 1:11ae12d41082 | 763 | * Remove the private callback and call the onDisableAllPassword callback. |
| rosarium | 1:11ae12d41082 | 764 | * @param nfc Object triggering the command. |
| rosarium | 1:11ae12d41082 | 765 | * @param status Command status. |
| rosarium | 1:11ae12d41082 | 766 | */ |
| rosarium | 1:11ae12d41082 | 767 | void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 768 | nfc->mComponentCallback=NULL; |
| rosarium | 1:11ae12d41082 | 769 | mI2CPwd=NULL; |
| rosarium | 1:11ae12d41082 | 770 | nfc->getCallback()->onDisableAllPassword(nfc,status); |
| rosarium | 1:11ae12d41082 | 771 | }//onFinish |
| rosarium | 1:11ae12d41082 | 772 | |
| rosarium | 1:11ae12d41082 | 773 | }; |
| rosarium | 1:11ae12d41082 | 774 | |
| rosarium | 1:11ae12d41082 | 775 | |
| rosarium | 1:11ae12d41082 | 776 | /** |
| rosarium | 1:11ae12d41082 | 777 | * Object containing the callback chain needed to remove the password request |
| rosarium | 1:11ae12d41082 | 778 | */ |
| rosarium | 1:11ae12d41082 | 779 | RemoveAllPasswordCallback mRemoveAllPasswordCallback; |
| rosarium | 1:11ae12d41082 | 780 | friend class RemoveAllPasswordCallback; |
| rosarium | 1:11ae12d41082 | 781 | |
| rosarium | 1:11ae12d41082 | 782 | /** |
| rosarium | 1:11ae12d41082 | 783 | * This class permits to set the tag as read/write only |
| rosarium | 1:11ae12d41082 | 784 | * This class is equivalent to calling the methods: |
| rosarium | 1:11ae12d41082 | 785 | * <ul> |
| rosarium | 1:11ae12d41082 | 786 | * <li> Verify(i2c) </li> |
| rosarium | 1:11ae12d41082 | 787 | * <li> EnablePermanentState(Read/write) </li> |
| rosarium | 1:11ae12d41082 | 788 | * </ul> |
| rosarium | 1:11ae12d41082 | 789 | * or: |
| rosarium | 1:11ae12d41082 | 790 | * <ul> |
| rosarium | 1:11ae12d41082 | 791 | * <li> Verify(i2c) </li> |
| rosarium | 1:11ae12d41082 | 792 | * <li> DisablePermanentState</li> |
| rosarium | 1:11ae12d41082 | 793 | * <li> DisableVerificationRequirement(Read/write) </li> |
| rosarium | 1:11ae12d41082 | 794 | * </ul> |
| rosarium | 1:11ae12d41082 | 795 | */ |
| rosarium | 1:11ae12d41082 | 796 | class ChangeAccessStateCallback : public Nfc::Callbacks{ |
| rosarium | 1:11ae12d41082 | 797 | |
| rosarium | 1:11ae12d41082 | 798 | public: |
| rosarium | 1:11ae12d41082 | 799 | |
| rosarium | 1:11ae12d41082 | 800 | typedef enum{ |
| rosarium | 1:11ae12d41082 | 801 | WRITE, |
| rosarium | 1:11ae12d41082 | 802 | READ |
| rosarium | 1:11ae12d41082 | 803 | }AccessType_t; |
| rosarium | 1:11ae12d41082 | 804 | |
| rosarium | 1:11ae12d41082 | 805 | /** |
| rosarium | 1:11ae12d41082 | 806 | * Build the chain of callbacks. |
| rosarium | 1:11ae12d41082 | 807 | */ |
| rosarium | 1:11ae12d41082 | 808 | ChangeAccessStateCallback():mType(WRITE),mEnable(false){} |
| rosarium | 1:11ae12d41082 | 809 | |
| rosarium | 1:11ae12d41082 | 810 | /** |
| rosarium | 1:11ae12d41082 | 811 | * Set the access to enable/disable an access type. |
| rosarium | 1:11ae12d41082 | 812 | * @param type Access type. |
| rosarium | 1:11ae12d41082 | 813 | * @param enable True to enable the state, False to disable it. |
| rosarium | 1:11ae12d41082 | 814 | */ |
| rosarium | 1:11ae12d41082 | 815 | void changeAccessState(AccessType_t type,bool enable){ |
| rosarium | 1:11ae12d41082 | 816 | mType=type; |
| rosarium | 1:11ae12d41082 | 817 | mEnable=enable; |
| rosarium | 1:11ae12d41082 | 818 | } |
| rosarium | 1:11ae12d41082 | 819 | |
| rosarium | 1:11ae12d41082 | 820 | virtual void onVerified(Nfc *nfc,NFC_StatusTypeDef status, |
| rosarium | 1:11ae12d41082 | 821 | PasswordType_t,const uint8_t*){ |
| rosarium | 1:11ae12d41082 | 822 | if(status!=NFC_SUCCESS) |
| rosarium | 1:11ae12d41082 | 823 | return onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 824 | |
| rosarium | 1:11ae12d41082 | 825 | if(mEnable){ |
| rosarium | 1:11ae12d41082 | 826 | nfc->DisablePermanentState(mType==WRITE? WritePwd : ReadPwd); |
| rosarium | 1:11ae12d41082 | 827 | }else |
| rosarium | 1:11ae12d41082 | 828 | nfc->EnablePermanentState(mType==WRITE? WritePwd : ReadPwd); |
| rosarium | 1:11ae12d41082 | 829 | |
| rosarium | 1:11ae12d41082 | 830 | } |
| rosarium | 1:11ae12d41082 | 831 | |
| rosarium | 1:11ae12d41082 | 832 | virtual void onDisablePermanentState(Nfc *nfc, NFC_StatusTypeDef status, |
| rosarium | 1:11ae12d41082 | 833 | PasswordType_t type ){ |
| rosarium | 1:11ae12d41082 | 834 | if(status!=NFC_SUCCESS) |
| rosarium | 1:11ae12d41082 | 835 | return onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 836 | |
| rosarium | 1:11ae12d41082 | 837 | nfc->DisableVerificationRequirement(type); |
| rosarium | 1:11ae12d41082 | 838 | } |
| rosarium | 1:11ae12d41082 | 839 | |
| rosarium | 1:11ae12d41082 | 840 | virtual void onDisableVerificationRequirement(Nfc *nfc , NFC_StatusTypeDef status, |
| rosarium | 1:11ae12d41082 | 841 | PasswordType_t ){ |
| rosarium | 1:11ae12d41082 | 842 | onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 843 | } |
| rosarium | 1:11ae12d41082 | 844 | |
| rosarium | 1:11ae12d41082 | 845 | virtual void onEnablePermanentState(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t ){ |
| rosarium | 1:11ae12d41082 | 846 | onFinishCommand(nfc,status); |
| rosarium | 1:11ae12d41082 | 847 | } |
| rosarium | 1:11ae12d41082 | 848 | |
| rosarium | 1:11ae12d41082 | 849 | |
| rosarium | 1:11ae12d41082 | 850 | private: |
| rosarium | 1:11ae12d41082 | 851 | |
| rosarium | 1:11ae12d41082 | 852 | /** |
| rosarium | 1:11ae12d41082 | 853 | * Remove the private callback and call the user callback. |
| rosarium | 1:11ae12d41082 | 854 | * @param nfc Object triggering the command. |
| rosarium | 1:11ae12d41082 | 855 | * @param status Command status. |
| rosarium | 1:11ae12d41082 | 856 | */ |
| rosarium | 1:11ae12d41082 | 857 | void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){ |
| rosarium | 1:11ae12d41082 | 858 | nfc->mComponentCallback=NULL; |
| rosarium | 1:11ae12d41082 | 859 | if(mEnable){ |
| rosarium | 1:11ae12d41082 | 860 | if(mType==READ){ |
| rosarium | 1:11ae12d41082 | 861 | //enable read = disable write only |
| rosarium | 1:11ae12d41082 | 862 | nfc->getCallback()->onDisableWriteOnly(nfc,status); |
| rosarium | 1:11ae12d41082 | 863 | }else |
| rosarium | 1:11ae12d41082 | 864 | //enable write = disable read only |
| rosarium | 1:11ae12d41082 | 865 | nfc->getCallback()->onDisableReadOnly(nfc,status); |
| rosarium | 1:11ae12d41082 | 866 | }else{ |
| rosarium | 1:11ae12d41082 | 867 | if(mType==WRITE){ |
| rosarium | 1:11ae12d41082 | 868 | //disable write = enable read only |
| rosarium | 1:11ae12d41082 | 869 | nfc->getCallback()->onEnableReadOnly(nfc,status); |
| rosarium | 1:11ae12d41082 | 870 | }else{ |
| rosarium | 1:11ae12d41082 | 871 | // |
| rosarium | 1:11ae12d41082 | 872 | nfc->getCallback()->onEnableWriteOnly(nfc,status); |
| rosarium | 1:11ae12d41082 | 873 | } |
| rosarium | 1:11ae12d41082 | 874 | }//if-else enable |
| rosarium | 1:11ae12d41082 | 875 | }//onFinish |
| rosarium | 1:11ae12d41082 | 876 | |
| rosarium | 1:11ae12d41082 | 877 | AccessType_t mType; |
| rosarium | 1:11ae12d41082 | 878 | bool mEnable; |
| rosarium | 1:11ae12d41082 | 879 | |
| rosarium | 1:11ae12d41082 | 880 | }; |
| rosarium | 1:11ae12d41082 | 881 | |
| rosarium | 1:11ae12d41082 | 882 | |
| rosarium | 1:11ae12d41082 | 883 | /** |
| rosarium | 1:11ae12d41082 | 884 | * Object containing the callback chain needed to change the access state |
| rosarium | 1:11ae12d41082 | 885 | */ |
| rosarium | 1:11ae12d41082 | 886 | ChangeAccessStateCallback mChangeAccessStateCallback; |
| rosarium | 1:11ae12d41082 | 887 | friend class ChangeAccessStateCallback; |
| rosarium | 1:11ae12d41082 | 888 | |
| rosarium | 1:11ae12d41082 | 889 | }; |
| rosarium | 1:11ae12d41082 | 890 | |
| rosarium | 1:11ae12d41082 | 891 | #endif /* __NFC_CLASS_H */ |
| rosarium | 1:11ae12d41082 | 892 | |
| rosarium | 1:11ae12d41082 | 893 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
