47 #define LOG_GROUP NFC_LOG_GROUP_GENERAL
48 #define LOG_CATEGORY "libnfc.general"
51 string_as_boolean(
const char *s,
bool *value)
55 if ((strcmp(s,
"yes") == 0) ||
56 (strcmp(s,
"true") == 0) ||
57 (strcmp(s,
"1") == 0)) {
62 if ((strcmp(s,
"no") == 0) ||
63 (strcmp(s,
"false") == 0) ||
64 (strcmp(s,
"0") == 0)) {
82 res->allow_autoscan =
true;
83 res->allow_intrusive_scan =
false;
91 for (
int i = 0; i < MAX_USER_DEFINED_DEVICES; i++) {
92 strcpy(res->user_defined_devices[i].name,
"");
93 strcpy(res->user_defined_devices[i].connstring,
"");
94 res->user_defined_devices[i].optional =
false;
96 res->user_defined_device_count = 0;
100 char *envvar = getenv(
"LIBNFC_DEFAULT_DEVICE");
102 strcpy(res->user_defined_devices[0].name,
"user defined default device");
103 strcpy(res->user_defined_devices[0].connstring, envvar);
104 res->user_defined_device_count++;
117 envvar = getenv(
"LIBNFC_INTRUSIVE_SCAN");
118 string_as_boolean(envvar, &(res->allow_intrusive_scan));
121 envvar = getenv(
"LIBNFC_LOG_LEVEL");
123 res->log_level = atoi(envvar);
132 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_NONE,
"log_level is set to %"PRIu32, res->log_level);
134 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"log_level is set to %"PRIu32, res->log_level);
136 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"allow_autoscan is set to %s", (res->allow_autoscan) ?
"true" :
"false");
137 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"allow_intrusive_scan is set to %s", (res->allow_intrusive_scan) ?
"true" :
"false");
139 log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"%d device(s) defined by user", res->user_defined_device_count);
140 for (uint32_t i = 0; i < res->user_defined_device_count; i++) {
141 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);
154 prepare_initiator_data(
const nfc_modulation nm, uint8_t **ppbtInitiatorData,
size_t *pszInitiatorData)
157 case NMT_ISO14443B: {
159 *ppbtInitiatorData = (uint8_t *)
"\x00";
160 *pszInitiatorData = 1;
163 case NMT_ISO14443BI: {
165 *ppbtInitiatorData = (uint8_t *)
"\x01\x0b\x3f\x80";
166 *pszInitiatorData = 4;
169 case NMT_ISO14443B2SR: {
171 *ppbtInitiatorData = (uint8_t *)
"\x0b";
172 *pszInitiatorData = 1;
175 case NMT_ISO14443B2CT: {
177 *ppbtInitiatorData = (uint8_t *)
"\x9F\xFF\xFF";
178 *pszInitiatorData = 3;
183 *ppbtInitiatorData = (uint8_t *)
"\x00\xff\xff\x01\x00";
184 *pszInitiatorData = 5;
190 *ppbtInitiatorData = NULL;
191 *pszInitiatorData = 0;
197 connstring_decode(
const nfc_connstring connstring,
const char *driver_name,
const char *bus_name,
char **pparam1,
char **pparam2)
199 if (driver_name == NULL) {
202 if (bus_name == NULL) {
205 int n = strlen(connstring) + 1;
206 char *param0 = malloc(n);
207 if (param0 == NULL) {
211 char *param1 = malloc(n);
212 if (param1 == NULL) {
217 char *param2 = malloc(n);
218 if (param2 == NULL) {
226 snprintf(format,
sizeof(format),
"%%%i[^:]:%%%i[^:]:%%%i[^:]", n - 1, n - 1, n - 1);
227 int res = sscanf(connstring, format, param0, param1, param2);
229 if (res < 1 || ((0 != strcmp(param0, driver_name)) &&
230 (bus_name != NULL) &&
231 (0 != strcmp(param0, bus_name)))) {
235 if (pparam1 != NULL) {
245 if (pparam2 != NULL) {
Internal defines and macros.
NFC modulation structure.
char nfc_connstring[NFC_BUFSIZE_CONNSTRING]
NFC library context Struct which contains internal options, references, pointers, etc...