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 /** 22 * @brief DiscoveryConfiguration is the data class 23 * which holds RF tech mode and Disc Frequency values 24 */ 25 class DiscoveryConfiguration { 26 public: 27 uint8_t mRfTechMode; 28 uint8_t mDiscFrequency; DiscoveryConfiguration(uint8_t rfTechMode,uint8_t discFrequency)29 DiscoveryConfiguration(uint8_t rfTechMode, uint8_t discFrequency) { 30 mRfTechMode = rfTechMode; 31 mDiscFrequency = discFrequency; 32 }; 33 }; 34 35 /** 36 * @brief NciDiscoveryCommandBuilder class handles the RF Discovery 37 * command, parses the command and identifies the RF tech mode 38 * and frequency. It helps to alter the configuration and build 39 * the command 40 */ 41 class NciDiscoveryCommandBuilder { 42 private: 43 vector<DiscoveryConfiguration> mRfDiscoverConfiguration; 44 45 /***************************************************************************** 46 * 47 * Function parse 48 * 49 * Description It parse the RF discovery commands and filters find the 50 * configurations 51 * 52 * Parameters data - RF discovery command 53 * 54 * Returns return true if parse is successful otherwise false 55 * 56 ****************************************************************************/ 57 bool parse(vector<uint8_t> data); 58 59 /***************************************************************************** 60 * 61 * Function removeListenParams 62 * 63 * Description Removes the listen mode from the configuration list 64 * 65 * Returns void 66 * 67 ****************************************************************************/ 68 void removeListenParams(); 69 70 /***************************************************************************** 71 * 72 * Function addObserveModeParams 73 * 74 * Description Adds Observe mode to the config list 75 * 76 * Returns void 77 * 78 ****************************************************************************/ 79 void addObserveModeParams(); 80 81 /***************************************************************************** 82 * 83 * Function build 84 * 85 * Description It frames the RF discovery command from the config list 86 * 87 * Returns return the discovery command 88 * 89 ****************************************************************************/ 90 vector<uint8_t> build(); 91 92 /***************************************************************************** 93 * 94 * Function isDiscoveryCommand 95 * 96 * Description Checks the command is RF discovery command or not 97 * 98 * Parameters data - Any command 99 * 100 * Returns return true if the command is RF discovery command 101 * otherwise false 102 * 103 ****************************************************************************/ 104 bool isDiscoveryCommand(vector<uint8_t> data); 105 106 #if (NXP_UNIT_TEST == TRUE) 107 /* 108 Friend class is used to test private function's of 109 NciDiscoveryCommandBuilder 110 */ 111 friend class NciDiscoveryCommandBuilderTest; 112 #endif 113 public: 114 /***************************************************************************** 115 * 116 * Function reConfigRFDiscCmd 117 * 118 * Description It parse the discovery command and alter the configuration 119 * to enable Observe Mode 120 * 121 * Parameters data - RF discovery command 122 * 123 * Returns return the discovery command for Observe mode 124 * 125 ****************************************************************************/ 126 vector<uint8_t> reConfigRFDiscCmd(uint16_t data_len, const uint8_t* p_data); 127 }; 128