1 /* 2 * Copyright 2024 NXP 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <vector> 18 19 using namespace std; 20 21 typedef void(reader_poll_info_callback_t)(uint16_t data_len, uint8_t* p_data); 22 23 /** 24 * @brief This class handles the parsing of Lx notifications and 25 * send reader poll info notification's. It identifis A, B and F 26 * Modulation event's and RF ON & OFF event's, all the other 27 * notifications it considers it as Unknown event's 28 * 29 */ 30 class ReaderPollConfigParser { 31 private: 32 reader_poll_info_callback_t* callback = nullptr; 33 uint8_t lastKnownGain = 0x00; 34 uint8_t lastKnownModEvent = 0x00; 35 36 /***************************************************************************** 37 * 38 * Function getWellKnownModEventData 39 * 40 * Description Frames Well known type reader poll info notification 41 * 42 * Parameters event - Event type A, B & F 43 * timeStamp - time stamp of the event 44 * gain - RSSI value 45 * data - data contains REQ, WUP and AFI 46 * 47 * Returns Returns Well known type reader poll info notification 48 * 49 ****************************************************************************/ 50 vector<uint8_t> getWellKnownModEventData(uint8_t event, 51 vector<uint8_t> timeStamp, 52 uint8_t gain, vector<uint8_t> data); 53 54 /***************************************************************************** 55 * 56 * Function getRFEventData 57 * 58 * Description Frames Well known type reader poll info notification 59 * 60 * Parameters timeStamp - time stamp of the event 61 * gain - RSSI value 62 * rfState - 0x00 for RF OFF, 0x01 for RF ON 63 * 64 * Returns Returns RF State reader poll info notification 65 * 66 ****************************************************************************/ 67 vector<uint8_t> getRFEventData(vector<uint8_t> timeStamp, uint8_t gain, 68 bool rfState); 69 70 /***************************************************************************** 71 * 72 * Function getUnknownEvent 73 * 74 * Description Frames Unknown event type reader poll info notification 75 * 76 * Parameters data - Data bytes of Unknown event 77 * timeStamp - time stamp of the event 78 * gain - RSSI value 79 * 80 * Returns Returns Unknown type reader poll info notification 81 * 82 ***************************************************************************/ 83 vector<uint8_t> getUnknownEvent(vector<uint8_t> data, 84 vector<uint8_t> timeStamp, uint8_t gain); 85 86 /***************************************************************************** 87 * 88 * Function getEvent 89 * 90 * Description It identifies the type of event and gets the reader poll 91 * info 92 * notification 93 * 94 * Parameters p_event - Vector Lx Notification 95 * isCmaEvent - true if it CMA event otherwise false 96 * 97 * Returns This function return reader poll info notification 98 * 99 ****************************************************************************/ 100 vector<uint8_t> getEvent(vector<uint8_t> p_event, bool isCmaEvent); 101 102 /***************************************************************************** 103 * 104 * Function notifyPollingLoopInfoEvent 105 * 106 * Description It sends polling info notification to upper layer 107 * 108 * Parameters p_data - Polling loop info notification 109 * 110 * Returns void 111 * 112 ****************************************************************************/ 113 void notifyPollingLoopInfoEvent(vector<uint8_t> p_data); 114 115 #if (NXP_UNIT_TEST == TRUE) 116 /* 117 Friend class is used to test private function's of ReaderPollConfigParser 118 */ 119 friend class ReaderPollConfigParserTest; 120 #endif 121 122 public: 123 /***************************************************************************** 124 * 125 * Function parseAndSendReaderPollInfo 126 * 127 * Description Function to parse Lx Notification & Send Reader Poll info 128 * notification 129 * 130 * Parameters p_ntf - Lx Notification 131 * p_len - Notification length 132 * 133 * Returns This function return true in case of success 134 * In case of failure returns false. 135 * 136 ****************************************************************************/ 137 bool parseAndSendReaderPollInfo(uint8_t* p_ntf, uint16_t p_len); 138 139 /***************************************************************************** 140 * 141 * Function parseAndSendReaderPollInfo 142 * 143 * Description Function to check it is Lx Notification or not 144 * 145 * Parameters p_ntf - Lx Notification 146 * p_len - Notification length 147 * 148 * Returns This function return true if it is Lx otherwise false 149 * 150 ****************************************************************************/ 151 bool isLxNotification(uint8_t* p_ntf, uint16_t p_len); 152 153 /***************************************************************************** 154 * 155 * Function setReaderPollCallBack 156 * 157 * Description Function to set the callback, It will be used to notify 158 * each reader polling data notifications 159 * 160 * Parameters callback - nfc data callback object 161 * 162 * Returns void 163 * 164 ****************************************************************************/ 165 void setReaderPollCallBack(reader_poll_info_callback_t* callback); 166 }; 167