46 #define LOG_GROUP NFC_LOG_GROUP_GENERAL
47 #define LOG_CATEGORY "libnfc.general"
50 string_as_boolean(
const char *s,
bool *value)
54 if ((strcmp(s,
"yes") == 0) ||
55 (strcmp(s,
"true") == 0) ||
56 (strcmp(s,
"1") == 0)) {
61 if ((strcmp(s,
"no") == 0) ||
62 (strcmp(s,
"false") == 0) ||
63 (strcmp(s,
"0") == 0)) {
81 res->allow_autoscan =
true;
82 res->allow_intrusive_scan =
false;
90 for (
int i = 0; i < MAX_USER_DEFINED_DEVICES; i++) {
91 strcpy(res->user_defined_devices[i].name,
"");
92 strcpy(res->user_defined_devices[i].connstring,
"");
93 res->user_defined_devices[i].optional =
false;
95 res->user_defined_device_count = 0;
99 char *envvar = getenv(
"LIBNFC_DEFAULT_DEVICE");
101 strcpy(res->user_defined_devices[0].name,
"user defined default device");
102 strcpy(res->user_defined_devices[0].connstring, envvar);
103 res->user_defined_device_count++;
116 envvar = getenv(
"LIBNFC_INTRUSIVE_SCAN");
117 string_as_boolean(envvar, &(res->allow_intrusive_scan));
120 envvar = getenv(
"LIBNFC_LOG_LEVEL");
122 res->log_level = atoi(envvar);
131 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_NONE,
"log_level is set to %"PRIu32, res->log_level);
133 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"log_level is set to %"PRIu32, res->log_level);
135 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"allow_autoscan is set to %s", (res->allow_autoscan) ?
"true" :
"false");
136 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"allow_intrusive_scan is set to %s", (res->allow_intrusive_scan) ?
"true" :
"false");
138 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"%d device(s) defined by user", res->user_defined_device_count);
139 for (uint32_t i = 0; i < res->user_defined_device_count; i++) {
140 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
" #%d name: \"%s\", connstring: \"%s\"", i, res->user_defined_devices[i].name, res->user_defined_devices[i].connstring);
153 prepare_initiator_data(
const nfc_modulation nm, uint8_t **ppbtInitiatorData,
size_t *pszInitiatorData)
156 case NMT_ISO14443B: {
158 *ppbtInitiatorData = (uint8_t *)
"\x00";
159 *pszInitiatorData = 1;
162 case NMT_ISO14443BI: {
164 *ppbtInitiatorData = (uint8_t *)
"\x01\x0b\x3f\x80";
165 *pszInitiatorData = 4;
168 case NMT_ISO14443B2SR: {
170 *ppbtInitiatorData = (uint8_t *)
"\x0b";
171 *pszInitiatorData = 1;
174 case NMT_ISO14443B2CT: {
176 *ppbtInitiatorData = (uint8_t *)
"\x9F\xFF\xFF";
177 *pszInitiatorData = 3;
182 *ppbtInitiatorData = (uint8_t *)
"\x00\xff\xff\x01\x00";
183 *pszInitiatorData = 5;
189 *ppbtInitiatorData = NULL;
190 *pszInitiatorData = 0;
196 connstring_decode(
const nfc_connstring connstring,
const char *driver_name,
const char *bus_name,
char **pparam1,
char **pparam2)
198 if (driver_name == NULL) {
201 if (bus_name == NULL) {
204 int n = strlen(connstring) + 1;
205 char *param0 = malloc(n);
206 if (param0 == NULL) {
210 char *param1 = malloc(n);
211 if (param1 == NULL) {
216 char *param2 = malloc(n);
217 if (param2 == NULL) {
225 snprintf(format,
sizeof(format),
"%%%i[^:]:%%%i[^:]:%%%i[^:]", n - 1, n - 1, n - 1);
226 int res = sscanf(connstring, format, param0, param1, param2);
228 if (res < 1 || ((0 != strcmp(param0, driver_name)) &&
229 (bus_name != NULL) &&
230 (0 != strcmp(param0, bus_name)))) {
234 if (pparam1 != NULL) {
244 if (pparam2 != NULL) {