1 /*
2  * Copyright 2017 The Android Open Source Project
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 #pragma once
17 
18 #include <string>
19 #include <vector>
20 
21 #include <config.h>
22 
23 /* Configs from libnfc-nci.conf */
24 #define NAME_NFC_DEBUG_ENABLED "NFC_DEBUG_ENABLED"
25 #define NAME_NFA_STORAGE "NFA_STORAGE"
26 #define NAME_PRESERVE_STORAGE "PRESERVE_STORAGE"
27 #define NAME_POLLING_TECH_MASK "POLLING_TECH_MASK"
28 #define NAME_P2P_LISTEN_TECH_MASK "P2P_LISTEN_TECH_MASK"
29 #define NAME_UICC_LISTEN_TECH_MASK "UICC_LISTEN_TECH_MASK"
30 #define NAME_HOST_LISTEN_TECH_MASK "HOST_LISTEN_TECH_MASK"
31 #define NAME_NFA_DM_CFG "NFA_DM_CFG"
32 #define NAME_SCREEN_OFF_POWER_STATE "SCREEN_OFF_POWER_STATE"
33 #define NAME_NFA_MAX_EE_SUPPORTED "NFA_MAX_EE_SUPPORTED"
34 #define NAME_NFA_DM_DISC_DURATION_POLL "NFA_DM_DISC_DURATION_POLL"
35 #define NAME_POLL_FREQUENCY "POLL_FREQUENCY"
36 #define NAME_NFA_AID_BLOCK_ROUTE "NFA_AID_BLOCK_ROUTE"
37 #define NAME_AID_FOR_EMPTY_SELECT "AID_FOR_EMPTY_SELECT"
38 #define NAME_AID_MATCHING_MODE "AID_MATCHING_MODE"
39 #define NAME_OFFHOST_AID_ROUTE_PWR_STATE "OFFHOST_AID_ROUTE_PWR_STATE"
40 #define NAME_LEGACY_MIFARE_READER "LEGACY_MIFARE_READER"
41 #define NAME_RECOVERY_OPTION "RECOVERY_OPTION"
42 #define NAME_ALWAYS_ON_SET_EE_POWER_AND_LINK_CONF \
43   "ALWAYS_ON_SET_EE_POWER_AND_LINK_CONF"
44 
45 /* Configs from vendor interface */
46 #define NAME_NFA_POLL_BAIL_OUT_MODE "NFA_POLL_BAIL_OUT_MODE"
47 #define NAME_PRESENCE_CHECK_ALGORITHM "PRESENCE_CHECK_ALGORITHM"
48 #define NAME_NFA_PROPRIETARY_CFG "NFA_PROPRIETARY_CFG"
49 #define NAME_DEFAULT_OFFHOST_ROUTE "DEFAULT_OFFHOST_ROUTE"
50 #define NAME_OFFHOST_ROUTE_ESE "OFFHOST_ROUTE_ESE"
51 #define NAME_OFFHOST_ROUTE_UICC "OFFHOST_ROUTE_UICC"
52 #define NAME_DEFAULT_NFCF_ROUTE "DEFAULT_NFCF_ROUTE"
53 #define NAME_DEFAULT_SYS_CODE "DEFAULT_SYS_CODE"
54 #define NAME_DEFAULT_SYS_CODE_ROUTE "DEFAULT_SYS_CODE_ROUTE"
55 #define NAME_DEFAULT_SYS_CODE_PWR_STATE "DEFAULT_SYS_CODE_PWR_STATE"
56 #define NAME_DEFAULT_ROUTE "DEFAULT_ROUTE"
57 #define NAME_OFF_HOST_ESE_PIPE_ID "OFF_HOST_ESE_PIPE_ID"
58 #define NAME_OFF_HOST_SIM_PIPE_ID "OFF_HOST_SIM_PIPE_ID"
59 #define NAME_ISO_DEP_MAX_TRANSCEIVE "ISO_DEP_MAX_TRANSCEIVE"
60 #define NAME_DEVICE_HOST_WHITE_LIST "DEVICE_HOST_WHITE_LIST"
61 #define NAME_DEFAULT_ISODEP_ROUTE "DEFAULT_ISODEP_ROUTE"
62 
63 class NfcConfig {
64  public:
65   static bool hasKey(const std::string& key);
66   static std::string getString(const std::string& key);
67   static std::string getString(const std::string& key,
68                                std::string default_value);
69   static unsigned getUnsigned(const std::string& key);
70   static unsigned getUnsigned(const std::string& key, unsigned default_value);
71   static std::vector<uint8_t> getBytes(const std::string& key);
72   static void clear();
73 
74  private:
75   void loadConfig();
76   static NfcConfig& getInstance();
77   NfcConfig();
78 
79   ConfigFile config_;
80 };
81