^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for NXP PN533 NFC Chip - core functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2011 Instituto Nokia de Tecnologia
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2012-2013 Tieto Poland
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/nfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/nfc/nfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "pn533.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define VERSION "0.3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* How much time we spend listening for initiators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define PN533_LISTEN_TIME 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Delay between each poll frame (ms) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PN533_POLL_INTERVAL 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* structs for pn533 commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* PN533_CMD_GET_FIRMWARE_VERSION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct pn533_fw_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) u8 ic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u8 ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u8 rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u8 support;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* PN533_CMD_RF_CONFIGURATION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define PN533_CFGITEM_RF_FIELD 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define PN533_CFGITEM_TIMING 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define PN533_CFGITEM_MAX_RETRIES 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define PN533_CFGITEM_PASORI 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define PN533_CFGITEM_RF_FIELD_AUTO_RFCA 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define PN533_CFGITEM_RF_FIELD_ON 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define PN533_CFGITEM_RF_FIELD_OFF 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define PN533_CONFIG_TIMING_102 0xb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define PN533_CONFIG_TIMING_204 0xc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define PN533_CONFIG_TIMING_409 0xd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define PN533_CONFIG_TIMING_819 0xe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define PN533_CONFIG_MAX_RETRIES_NO_RETRY 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define PN533_CONFIG_MAX_RETRIES_ENDLESS 0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct pn533_config_max_retries {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u8 mx_rty_atr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u8 mx_rty_psl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u8 mx_rty_passive_act;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct pn533_config_timing {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u8 rfu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u8 atr_res_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u8 dep_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* PN533_CMD_IN_LIST_PASSIVE_TARGET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* felica commands opcode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define PN533_FELICA_OPC_SENSF_REQ 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define PN533_FELICA_OPC_SENSF_RES 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* felica SENSF_REQ parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define PN533_FELICA_SENSF_SC_ALL 0xFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define PN533_FELICA_SENSF_RC_SYSTEM_CODE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define PN533_FELICA_SENSF_RC_ADVANCED_PROTOCOL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* type B initiator_data values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define PN533_TYPE_B_AFI_ALL_FAMILIES 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define PN533_TYPE_B_POLL_METHOD_TIMESLOT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define PN533_TYPE_B_POLL_METHOD_PROBABILISTIC 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) union pn533_cmd_poll_initdata {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u8 afi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u8 polling_method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) } __packed type_b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u8 opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __be16 sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u8 rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u8 tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) } __packed felica;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct pn533_poll_modulations {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u8 maxtg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u8 brty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) union pn533_cmd_poll_initdata initiator_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) } __packed data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) u8 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static const struct pn533_poll_modulations poll_mod[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) [PN533_POLL_MOD_106KBPS_A] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .maxtg = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .brty = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .len = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) [PN533_POLL_MOD_212KBPS_FELICA] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .maxtg = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .brty = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .initiator_data.felica = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .opcode = PN533_FELICA_OPC_SENSF_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .sc = PN533_FELICA_SENSF_SC_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .rc = PN533_FELICA_SENSF_RC_SYSTEM_CODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .tsn = 0x03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .len = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) [PN533_POLL_MOD_424KBPS_FELICA] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .maxtg = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .brty = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .initiator_data.felica = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .opcode = PN533_FELICA_OPC_SENSF_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .sc = PN533_FELICA_SENSF_SC_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .rc = PN533_FELICA_SENSF_RC_SYSTEM_CODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .tsn = 0x03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .len = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) [PN533_POLL_MOD_106KBPS_JEWEL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .maxtg = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .brty = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .len = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) [PN533_POLL_MOD_847KBPS_B] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .maxtg = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .brty = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .initiator_data.type_b = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .afi = PN533_TYPE_B_AFI_ALL_FAMILIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .polling_method =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) PN533_TYPE_B_POLL_METHOD_TIMESLOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .len = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) [PN533_LISTEN_MOD] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .len = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* PN533_CMD_IN_ATR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct pn533_cmd_activate_response {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) u8 nfcid3t[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) u8 didt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) u8 bst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) u8 brt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) u8 to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) u8 ppt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* optional */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) u8 gt[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct pn533_cmd_jump_dep_response {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) u8 tg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u8 nfcid3t[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u8 didt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) u8 bst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) u8 brt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) u8 to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) u8 ppt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* optional */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u8 gt[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct pn532_autopoll_resp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) u8 ln;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) u8 tg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) u8 tgdata[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* PN532_CMD_IN_AUTOPOLL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define PN532_AUTOPOLL_POLLNR_INFINITE 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define PN532_AUTOPOLL_PERIOD 0x03 /* in units of 150 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #define PN532_AUTOPOLL_TYPE_GENERIC_106 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define PN532_AUTOPOLL_TYPE_GENERIC_212 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define PN532_AUTOPOLL_TYPE_GENERIC_424 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define PN532_AUTOPOLL_TYPE_JEWEL 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define PN532_AUTOPOLL_TYPE_MIFARE 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #define PN532_AUTOPOLL_TYPE_FELICA212 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define PN532_AUTOPOLL_TYPE_FELICA424 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define PN532_AUTOPOLL_TYPE_ISOA 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define PN532_AUTOPOLL_TYPE_ISOB 0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #define PN532_AUTOPOLL_TYPE_DEP_PASSIVE_106 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #define PN532_AUTOPOLL_TYPE_DEP_PASSIVE_212 0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define PN532_AUTOPOLL_TYPE_DEP_PASSIVE_424 0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define PN532_AUTOPOLL_TYPE_DEP_ACTIVE_106 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #define PN532_AUTOPOLL_TYPE_DEP_ACTIVE_212 0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define PN532_AUTOPOLL_TYPE_DEP_ACTIVE_424 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* PN533_TG_INIT_AS_TARGET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define PN533_INIT_TARGET_PASSIVE 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define PN533_INIT_TARGET_DEP 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define PN533_INIT_TARGET_RESP_FRAME_MASK 0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define PN533_INIT_TARGET_RESP_ACTIVE 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define PN533_INIT_TARGET_RESP_DEP 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* The rule: value(high byte) + value(low byte) + checksum = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static inline u8 pn533_ext_checksum(u16 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return ~(u8)(((value & 0xFF00) >> 8) + (u8)(value & 0xFF)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* The rule: value + checksum = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static inline u8 pn533_std_checksum(u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return ~value + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* The rule: sum(data elements) + checksum = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static u8 pn533_std_data_checksum(u8 *data, int datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) u8 sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) for (i = 0; i < datalen; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sum += data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return pn533_std_checksum(sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void pn533_std_tx_frame_init(void *_frame, u8 cmd_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct pn533_std_frame *frame = _frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) frame->preamble = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) frame->start_frame = cpu_to_be16(PN533_STD_FRAME_SOF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) PN533_STD_FRAME_IDENTIFIER(frame) = PN533_STD_FRAME_DIR_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) PN533_FRAME_CMD(frame) = cmd_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) frame->datalen = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static void pn533_std_tx_frame_finish(void *_frame)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct pn533_std_frame *frame = _frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) frame->datalen_checksum = pn533_std_checksum(frame->datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) PN533_STD_FRAME_CHECKSUM(frame) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) pn533_std_data_checksum(frame->data, frame->datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) PN533_STD_FRAME_POSTAMBLE(frame) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static void pn533_std_tx_update_payload_len(void *_frame, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct pn533_std_frame *frame = _frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) frame->datalen += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static bool pn533_std_rx_frame_is_valid(void *_frame, struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) u8 checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct pn533_std_frame *stdf = _frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (stdf->start_frame != cpu_to_be16(PN533_STD_FRAME_SOF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (likely(!PN533_STD_IS_EXTENDED(stdf))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* Standard frame code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) dev->ops->rx_header_len = PN533_STD_FRAME_HEADER_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) checksum = pn533_std_checksum(stdf->datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (checksum != stdf->datalen_checksum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) checksum = pn533_std_data_checksum(stdf->data, stdf->datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (checksum != PN533_STD_FRAME_CHECKSUM(stdf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /* Extended */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct pn533_ext_frame *eif = _frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) dev->ops->rx_header_len = PN533_EXT_FRAME_HEADER_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) checksum = pn533_ext_checksum(be16_to_cpu(eif->datalen));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (checksum != eif->datalen_checksum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* check data checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) checksum = pn533_std_data_checksum(eif->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) be16_to_cpu(eif->datalen));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (checksum != PN533_EXT_FRAME_CHECKSUM(eif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) bool pn533_rx_frame_is_ack(void *_frame)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct pn533_std_frame *frame = _frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (frame->start_frame != cpu_to_be16(PN533_STD_FRAME_SOF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (frame->datalen != 0 || frame->datalen_checksum != 0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) EXPORT_SYMBOL_GPL(pn533_rx_frame_is_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static inline int pn533_std_rx_frame_size(void *frame)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct pn533_std_frame *f = frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* check for Extended Information frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (PN533_STD_IS_EXTENDED(f)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct pn533_ext_frame *eif = frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return sizeof(struct pn533_ext_frame)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) + be16_to_cpu(eif->datalen) + PN533_STD_FRAME_TAIL_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return sizeof(struct pn533_std_frame) + f->datalen +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) PN533_STD_FRAME_TAIL_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static u8 pn533_std_get_cmd_code(void *frame)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct pn533_std_frame *f = frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct pn533_ext_frame *eif = frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (PN533_STD_IS_EXTENDED(f))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return PN533_FRAME_CMD(eif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return PN533_FRAME_CMD(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) bool pn533_rx_frame_is_cmd_response(struct pn533 *dev, void *frame)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return (dev->ops->get_cmd_code(frame) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) PN533_CMD_RESPONSE(dev->cmd->code));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) EXPORT_SYMBOL_GPL(pn533_rx_frame_is_cmd_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static struct pn533_frame_ops pn533_std_frame_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) .tx_frame_init = pn533_std_tx_frame_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .tx_frame_finish = pn533_std_tx_frame_finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .tx_update_payload_len = pn533_std_tx_update_payload_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .tx_header_len = PN533_STD_FRAME_HEADER_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .tx_tail_len = PN533_STD_FRAME_TAIL_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) .rx_is_frame_valid = pn533_std_rx_frame_is_valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) .rx_frame_size = pn533_std_rx_frame_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) .rx_header_len = PN533_STD_FRAME_HEADER_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) .rx_tail_len = PN533_STD_FRAME_TAIL_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) .max_payload_len = PN533_STD_FRAME_MAX_PAYLOAD_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) .get_cmd_code = pn533_std_get_cmd_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static void pn533_build_cmd_frame(struct pn533 *dev, u8 cmd_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* payload is already there, just update datalen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) int payload_len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct pn533_frame_ops *ops = dev->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) skb_push(skb, ops->tx_header_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) skb_put(skb, ops->tx_tail_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) ops->tx_frame_init(skb->data, cmd_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) ops->tx_update_payload_len(skb->data, payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ops->tx_frame_finish(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static int pn533_send_async_complete(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct pn533_cmd *cmd = dev->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct sk_buff *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int status, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (!cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) dev_dbg(dev->dev, "%s: cmd not set\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) dev_kfree_skb(cmd->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) status = cmd->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) resp = cmd->resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) rc = cmd->complete_cb(dev, cmd->complete_cb_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) ERR_PTR(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /* when no response is set we got interrupted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (!resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) resp = ERR_PTR(-EINTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (!IS_ERR(resp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) skb_pull(resp, dev->ops->rx_header_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) skb_trim(resp, resp->len - dev->ops->rx_tail_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) rc = cmd->complete_cb(dev, cmd->complete_cb_context, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) dev->cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int __pn533_send_async(struct pn533 *dev, u8 cmd_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct sk_buff *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) pn533_send_async_complete_t complete_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) void *complete_cb_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct pn533_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) dev_dbg(dev->dev, "Sending command 0x%x\n", cmd_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (!cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) cmd->code = cmd_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) cmd->req = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) cmd->complete_cb = complete_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) cmd->complete_cb_context = complete_cb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) pn533_build_cmd_frame(dev, cmd_code, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) mutex_lock(&dev->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (!dev->cmd_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) dev->cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) rc = dev->phy_ops->send_frame(dev, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) dev->cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) dev->cmd_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) dev_dbg(dev->dev, "%s Queueing command 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) __func__, cmd_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) INIT_LIST_HEAD(&cmd->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) list_add_tail(&cmd->queue, &dev->cmd_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) mutex_unlock(&dev->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static int pn533_send_data_async(struct pn533 *dev, u8 cmd_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct sk_buff *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) pn533_send_async_complete_t complete_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) void *complete_cb_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) rc = __pn533_send_async(dev, cmd_code, req, complete_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) complete_cb_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static int pn533_send_cmd_async(struct pn533 *dev, u8 cmd_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct sk_buff *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) pn533_send_async_complete_t complete_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) void *complete_cb_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) rc = __pn533_send_async(dev, cmd_code, req, complete_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) complete_cb_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * pn533_send_cmd_direct_async
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * The function sends a piority cmd directly to the chip omitting the cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * queue. It's intended to be used by chaining mechanism of received responses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * where the host has to request every single chunk of data before scheduling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * next cmd from the queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static int pn533_send_cmd_direct_async(struct pn533 *dev, u8 cmd_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct sk_buff *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) pn533_send_async_complete_t complete_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) void *complete_cb_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct pn533_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (!cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) cmd->code = cmd_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) cmd->req = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) cmd->complete_cb = complete_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) cmd->complete_cb_context = complete_cb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) pn533_build_cmd_frame(dev, cmd_code, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) dev->cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) rc = dev->phy_ops->send_frame(dev, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) dev->cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static void pn533_wq_cmd_complete(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct pn533 *dev = container_of(work, struct pn533, cmd_complete_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) rc = pn533_send_async_complete(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (rc != -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) queue_work(dev->wq, &dev->cmd_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static void pn533_wq_cmd(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct pn533 *dev = container_of(work, struct pn533, cmd_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) struct pn533_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) mutex_lock(&dev->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (list_empty(&dev->cmd_queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) dev->cmd_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) mutex_unlock(&dev->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) cmd = list_first_entry(&dev->cmd_queue, struct pn533_cmd, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) list_del(&cmd->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) mutex_unlock(&dev->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) dev->cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) rc = dev->phy_ops->send_frame(dev, cmd->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) dev->cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) dev_kfree_skb(cmd->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) struct pn533_sync_cmd_response {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct sk_buff *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct completion done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static int pn533_send_sync_complete(struct pn533 *dev, void *_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct pn533_sync_cmd_response *arg = _arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) arg->resp = resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) complete(&arg->done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /* pn533_send_cmd_sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * Please note the req parameter is freed inside the function to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * limit a number of return value interpretations by the caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) * 1. negative in case of error during TX path -> req should be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * 2. negative in case of error during RX path -> req should not be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * as it's been already freed at the beginning of RX path by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * async_complete_cb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * 3. valid pointer in case of succesfult RX path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * A caller has to check a return value with IS_ERR macro. If the test pass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * the returned pointer is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static struct sk_buff *pn533_send_cmd_sync(struct pn533 *dev, u8 cmd_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct sk_buff *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) struct pn533_sync_cmd_response arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) init_completion(&arg.done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) rc = pn533_send_cmd_async(dev, cmd_code, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) pn533_send_sync_complete, &arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) dev_kfree_skb(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) wait_for_completion(&arg.done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return arg.resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static struct sk_buff *pn533_alloc_skb(struct pn533 *dev, unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) skb = alloc_skb(dev->ops->tx_header_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) size +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) dev->ops->tx_tail_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) skb_reserve(skb, dev->ops->tx_header_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct pn533_target_type_a {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) __be16 sens_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) u8 sel_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) u8 nfcid_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) u8 nfcid_data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) #define PN533_TYPE_A_SENS_RES_NFCID1(x) ((u8)((be16_to_cpu(x) & 0x00C0) >> 6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) #define PN533_TYPE_A_SENS_RES_SSD(x) ((u8)((be16_to_cpu(x) & 0x001F) >> 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) #define PN533_TYPE_A_SENS_RES_PLATCONF(x) ((u8)((be16_to_cpu(x) & 0x0F00) >> 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) #define PN533_TYPE_A_SENS_RES_SSD_JEWEL 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) #define PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL 0x0C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) #define PN533_TYPE_A_SEL_PROT(x) (((x) & 0x60) >> 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) #define PN533_TYPE_A_SEL_CASCADE(x) (((x) & 0x04) >> 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) #define PN533_TYPE_A_SEL_PROT_MIFARE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) #define PN533_TYPE_A_SEL_PROT_ISO14443 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) #define PN533_TYPE_A_SEL_PROT_DEP 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) #define PN533_TYPE_A_SEL_PROT_ISO14443_DEP 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static bool pn533_target_type_a_is_valid(struct pn533_target_type_a *type_a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) int target_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) u8 ssd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) u8 platconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (target_data_len < sizeof(struct pn533_target_type_a))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * The length check of nfcid[] and ats[] are not being performed because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * the values are not being used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) /* Requirement 4.6.3.3 from NFC Forum Digital Spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) ssd = PN533_TYPE_A_SENS_RES_SSD(type_a->sens_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) platconf = PN533_TYPE_A_SENS_RES_PLATCONF(type_a->sens_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) if ((ssd == PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) platconf != PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) (ssd != PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) platconf == PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) /* Requirements 4.8.2.1, 4.8.2.3, 4.8.2.5 and 4.8.2.7 from NFC Forum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (PN533_TYPE_A_SEL_CASCADE(type_a->sel_res) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (type_a->nfcid_len > NFC_NFCID1_MAXSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) static int pn533_target_found_type_a(struct nfc_target *nfc_tgt, u8 *tgt_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) int tgt_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) struct pn533_target_type_a *tgt_type_a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) tgt_type_a = (struct pn533_target_type_a *)tgt_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (!pn533_target_type_a_is_valid(tgt_type_a, tgt_data_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) switch (PN533_TYPE_A_SEL_PROT(tgt_type_a->sel_res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) case PN533_TYPE_A_SEL_PROT_MIFARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) nfc_tgt->supported_protocols = NFC_PROTO_MIFARE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) case PN533_TYPE_A_SEL_PROT_ISO14443:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) case PN533_TYPE_A_SEL_PROT_DEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) nfc_tgt->supported_protocols = NFC_PROTO_NFC_DEP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) case PN533_TYPE_A_SEL_PROT_ISO14443_DEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) NFC_PROTO_NFC_DEP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) nfc_tgt->sens_res = be16_to_cpu(tgt_type_a->sens_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) nfc_tgt->sel_res = tgt_type_a->sel_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) nfc_tgt->nfcid1_len = tgt_type_a->nfcid_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) memcpy(nfc_tgt->nfcid1, tgt_type_a->nfcid_data, nfc_tgt->nfcid1_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) struct pn533_target_felica {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) u8 pol_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) u8 opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) u8 nfcid2[NFC_NFCID2_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) u8 pad[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* optional */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) u8 syst_code[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) #define PN533_FELICA_SENSF_NFCID2_DEP_B1 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) #define PN533_FELICA_SENSF_NFCID2_DEP_B2 0xFE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static bool pn533_target_felica_is_valid(struct pn533_target_felica *felica,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) int target_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (target_data_len < sizeof(struct pn533_target_felica))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (felica->opcode != PN533_FELICA_OPC_SENSF_RES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) static int pn533_target_found_felica(struct nfc_target *nfc_tgt, u8 *tgt_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) int tgt_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) struct pn533_target_felica *tgt_felica;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) tgt_felica = (struct pn533_target_felica *)tgt_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (!pn533_target_felica_is_valid(tgt_felica, tgt_data_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) if ((tgt_felica->nfcid2[0] == PN533_FELICA_SENSF_NFCID2_DEP_B1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) (tgt_felica->nfcid2[1] == PN533_FELICA_SENSF_NFCID2_DEP_B2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) nfc_tgt->supported_protocols = NFC_PROTO_NFC_DEP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) nfc_tgt->supported_protocols = NFC_PROTO_FELICA_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) memcpy(nfc_tgt->sensf_res, &tgt_felica->opcode, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) nfc_tgt->sensf_res_len = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) memcpy(nfc_tgt->nfcid2, tgt_felica->nfcid2, NFC_NFCID2_MAXSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) nfc_tgt->nfcid2_len = NFC_NFCID2_MAXSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) struct pn533_target_jewel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) __be16 sens_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) u8 jewelid[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) static bool pn533_target_jewel_is_valid(struct pn533_target_jewel *jewel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) int target_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) u8 ssd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) u8 platconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (target_data_len < sizeof(struct pn533_target_jewel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) /* Requirement 4.6.3.3 from NFC Forum Digital Spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) ssd = PN533_TYPE_A_SENS_RES_SSD(jewel->sens_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) platconf = PN533_TYPE_A_SENS_RES_PLATCONF(jewel->sens_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) if ((ssd == PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) platconf != PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) (ssd != PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) platconf == PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) static int pn533_target_found_jewel(struct nfc_target *nfc_tgt, u8 *tgt_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) int tgt_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) struct pn533_target_jewel *tgt_jewel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) tgt_jewel = (struct pn533_target_jewel *)tgt_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (!pn533_target_jewel_is_valid(tgt_jewel, tgt_data_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) nfc_tgt->supported_protocols = NFC_PROTO_JEWEL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) nfc_tgt->sens_res = be16_to_cpu(tgt_jewel->sens_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) nfc_tgt->nfcid1_len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) memcpy(nfc_tgt->nfcid1, tgt_jewel->jewelid, nfc_tgt->nfcid1_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) struct pn533_type_b_prot_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) u8 bitrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) u8 fsci_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) u8 fwi_adc_fo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) #define PN533_TYPE_B_PROT_FCSI(x) (((x) & 0xF0) >> 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) #define PN533_TYPE_B_PROT_TYPE(x) (((x) & 0x0F) >> 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) #define PN533_TYPE_B_PROT_TYPE_RFU_MASK 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct pn533_type_b_sens_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) u8 opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) u8 nfcid[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) u8 appdata[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct pn533_type_b_prot_info prot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) #define PN533_TYPE_B_OPC_SENSB_RES 0x50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) struct pn533_target_type_b {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) struct pn533_type_b_sens_res sensb_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) u8 attrib_res_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) u8 attrib_res[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) static bool pn533_target_type_b_is_valid(struct pn533_target_type_b *type_b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) int target_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) if (target_data_len < sizeof(struct pn533_target_type_b))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) if (type_b->sensb_res.opcode != PN533_TYPE_B_OPC_SENSB_RES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (PN533_TYPE_B_PROT_TYPE(type_b->sensb_res.prot_info.fsci_type) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) PN533_TYPE_B_PROT_TYPE_RFU_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) static int pn533_target_found_type_b(struct nfc_target *nfc_tgt, u8 *tgt_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) int tgt_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) struct pn533_target_type_b *tgt_type_b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) tgt_type_b = (struct pn533_target_type_b *)tgt_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (!pn533_target_type_b_is_valid(tgt_type_b, tgt_data_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_B_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) static void pn533_poll_reset_mod_list(struct pn533 *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) static int pn533_target_found(struct pn533 *dev, u8 tg, u8 *tgdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) int tgdata_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) struct nfc_target nfc_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) dev_dbg(dev->dev, "%s: modulation=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) __func__, dev->poll_mod_curr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) if (tg != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) memset(&nfc_tgt, 0, sizeof(struct nfc_target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) switch (dev->poll_mod_curr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) case PN533_POLL_MOD_106KBPS_A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) rc = pn533_target_found_type_a(&nfc_tgt, tgdata, tgdata_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) case PN533_POLL_MOD_212KBPS_FELICA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) case PN533_POLL_MOD_424KBPS_FELICA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) rc = pn533_target_found_felica(&nfc_tgt, tgdata, tgdata_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) case PN533_POLL_MOD_106KBPS_JEWEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) rc = pn533_target_found_jewel(&nfc_tgt, tgdata, tgdata_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) case PN533_POLL_MOD_847KBPS_B:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) rc = pn533_target_found_type_b(&nfc_tgt, tgdata, tgdata_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) "Unknown current poll modulation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (!(nfc_tgt.supported_protocols & dev->poll_protocols)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) dev_dbg(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) "The Tg found doesn't have the desired protocol\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) dev_dbg(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) "Target found - supported protocols: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) nfc_tgt.supported_protocols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) dev->tgt_available_prots = nfc_tgt.supported_protocols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) pn533_poll_reset_mod_list(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) nfc_targets_found(dev->nfc_dev, &nfc_tgt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) static inline void pn533_poll_next_mod(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) dev->poll_mod_curr = (dev->poll_mod_curr + 1) % dev->poll_mod_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) static void pn533_poll_reset_mod_list(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) dev->poll_mod_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) static void pn533_poll_add_mod(struct pn533 *dev, u8 mod_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) dev->poll_mod_active[dev->poll_mod_count] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) (struct pn533_poll_modulations *)&poll_mod[mod_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) dev->poll_mod_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) static void pn533_poll_create_mod_list(struct pn533 *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) u32 im_protocols, u32 tm_protocols)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) pn533_poll_reset_mod_list(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if ((im_protocols & NFC_PROTO_MIFARE_MASK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) (im_protocols & NFC_PROTO_ISO14443_MASK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) (im_protocols & NFC_PROTO_NFC_DEP_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (im_protocols & NFC_PROTO_FELICA_MASK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) im_protocols & NFC_PROTO_NFC_DEP_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) pn533_poll_add_mod(dev, PN533_POLL_MOD_212KBPS_FELICA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) pn533_poll_add_mod(dev, PN533_POLL_MOD_424KBPS_FELICA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (im_protocols & NFC_PROTO_JEWEL_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_JEWEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) if (im_protocols & NFC_PROTO_ISO14443_B_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) pn533_poll_add_mod(dev, PN533_POLL_MOD_847KBPS_B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) if (tm_protocols)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) pn533_poll_add_mod(dev, PN533_LISTEN_MOD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) static int pn533_start_poll_complete(struct pn533 *dev, struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) u8 nbtg, tg, *tgdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) int rc, tgdata_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) /* Toggle the DEP polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (dev->poll_protocols & NFC_PROTO_NFC_DEP_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) dev->poll_dep = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) nbtg = resp->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) tg = resp->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) tgdata = &resp->data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) tgdata_len = resp->len - 2; /* nbtg + tg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (nbtg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) rc = pn533_target_found(dev, tg, tgdata, tgdata_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) /* We must stop the poll after a valid target found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) static struct sk_buff *pn533_alloc_poll_tg_frame(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) u8 *felica, *nfcid3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) u8 *gbytes = dev->gb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) size_t gbytes_len = dev->gb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) u8 felica_params[18] = {0x1, 0xfe, /* DEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* random */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 0xff, 0xff}; /* System code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) u8 mifare_params[6] = {0x1, 0x1, /* SENS_RES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 0x0, 0x0, 0x0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 0x40}; /* SEL_RES for DEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) unsigned int skb_len = 36 + /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) * mode (1), mifare (6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) * felica (18), nfcid3 (10), gb_len (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) gbytes_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 1; /* len Tk*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) skb = pn533_alloc_skb(dev, skb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) /* DEP support only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) skb_put_u8(skb, PN533_INIT_TARGET_DEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) /* MIFARE params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) skb_put_data(skb, mifare_params, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) /* Felica params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) felica = skb_put_data(skb, felica_params, 18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) get_random_bytes(felica + 2, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) /* NFCID3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) nfcid3 = skb_put_zero(skb, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) memcpy(nfcid3, felica, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) /* General bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) skb_put_u8(skb, gbytes_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) skb_put_data(skb, gbytes, gbytes_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) /* Len Tk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) skb_put_u8(skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) static void pn533_wq_tm_mi_recv(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) static struct sk_buff *pn533_build_response(struct pn533 *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) static int pn533_tm_get_data_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) u8 status, ret, mi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (IS_ERR(resp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) skb_queue_purge(&dev->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) status = resp->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) ret = status & PN533_CMD_RET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) mi = status & PN533_CMD_MI_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) skb_pull(resp, sizeof(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (ret != PN533_CMD_RET_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) skb_queue_tail(&dev->resp_q, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (mi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) queue_work(dev->wq, &dev->mi_tm_rx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) return -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) skb = pn533_build_response(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) return nfc_tm_data_received(dev->nfc_dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) nfc_tm_deactivated(dev->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) dev->tgt_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) skb_queue_purge(&dev->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) static void pn533_wq_tm_mi_recv(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) struct pn533 *dev = container_of(work, struct pn533, mi_tm_rx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) skb = pn533_alloc_skb(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) rc = pn533_send_cmd_direct_async(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) PN533_CMD_TG_GET_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) pn533_tm_get_data_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) static int pn533_tm_send_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) struct sk_buff *resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) static void pn533_wq_tm_mi_send(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) struct pn533 *dev = container_of(work, struct pn533, mi_tm_tx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) /* Grab the first skb in the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) skb = skb_dequeue(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) if (skb == NULL) { /* No more data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) /* Reset the queue for future use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) skb_queue_head_init(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) /* last entry - remove MI bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (skb_queue_len(&dev->fragment_skb) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) rc = pn533_send_cmd_direct_async(dev, PN533_CMD_TG_SET_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) skb, pn533_tm_send_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) rc = pn533_send_cmd_direct_async(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) PN533_CMD_TG_SET_META_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) skb, pn533_tm_send_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) if (rc == 0) /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) dev_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) "Error %d when trying to perform set meta data_exchange", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) dev->phy_ops->send_ack(dev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) queue_work(dev->wq, &dev->cmd_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) static void pn533_wq_tg_get_data(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) struct pn533 *dev = container_of(work, struct pn533, tg_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) skb = pn533_alloc_skb(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) rc = pn533_send_data_async(dev, PN533_CMD_TG_GET_DATA, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) pn533_tm_get_data_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) #define ATR_REQ_GB_OFFSET 17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) static int pn533_init_target_complete(struct pn533 *dev, struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) u8 mode, *cmd, comm_mode = NFC_COMM_PASSIVE, *gb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) size_t gb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (resp->len < ATR_REQ_GB_OFFSET + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) mode = resp->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) cmd = &resp->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) dev_dbg(dev->dev, "Target mode 0x%x len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) mode, resp->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) if ((mode & PN533_INIT_TARGET_RESP_FRAME_MASK) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) PN533_INIT_TARGET_RESP_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) comm_mode = NFC_COMM_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if ((mode & PN533_INIT_TARGET_RESP_DEP) == 0) /* Only DEP supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) gb = cmd + ATR_REQ_GB_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) gb_len = resp->len - (ATR_REQ_GB_OFFSET + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) rc = nfc_tm_activated(dev->nfc_dev, NFC_PROTO_NFC_DEP_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) comm_mode, gb, gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) "Error when signaling target activation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) dev->tgt_mode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) queue_work(dev->wq, &dev->tg_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) static void pn533_listen_mode_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) struct pn533 *dev = from_timer(dev, t, listen_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) dev_dbg(dev->dev, "Listen mode timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) dev->cancel_listen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) pn533_poll_next_mod(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) queue_delayed_work(dev->wq, &dev->poll_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) msecs_to_jiffies(PN533_POLL_INTERVAL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) static int pn533_rf_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) if (IS_ERR(resp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) rc = PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) nfc_err(dev->dev, "RF setting error %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) queue_delayed_work(dev->wq, &dev->poll_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) msecs_to_jiffies(PN533_POLL_INTERVAL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) static void pn533_wq_rf(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) struct pn533 *dev = container_of(work, struct pn533, rf_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) skb = pn533_alloc_skb(dev, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) skb_put_u8(skb, PN533_CFGITEM_RF_FIELD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) skb_put_u8(skb, PN533_CFGITEM_RF_FIELD_AUTO_RFCA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) rc = pn533_send_cmd_async(dev, PN533_CMD_RF_CONFIGURATION, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) pn533_rf_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) nfc_err(dev->dev, "RF setting error %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) static int pn533_poll_dep_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) struct pn533_cmd_jump_dep_response *rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) struct nfc_target nfc_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) u8 target_gt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) if (IS_ERR(resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) rsp = (struct pn533_cmd_jump_dep_response *)resp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) rc = rsp->status & PN533_CMD_RET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) if (rc != PN533_CMD_RET_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) /* Not target found, turn radio off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) queue_work(dev->wq, &dev->rf_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) dev_dbg(dev->dev, "Creating new target");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) nfc_target.nfcid1_len = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) memcpy(nfc_target.nfcid1, rsp->nfcid3t, nfc_target.nfcid1_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) rc = nfc_targets_found(dev->nfc_dev, &nfc_target, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) dev->tgt_available_prots = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) dev->tgt_active_prot = NFC_PROTO_NFC_DEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) /* ATR_RES general bytes are located at offset 17 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) target_gt_len = resp->len - 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) rc = nfc_set_remote_general_bytes(dev->nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) rsp->gt, target_gt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) rc = nfc_dep_link_is_up(dev->nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) dev->nfc_dev->targets[0].idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 0, NFC_RF_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) pn533_poll_reset_mod_list(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) #define PASSIVE_DATA_LEN 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) static int pn533_poll_dep(struct nfc_dev *nfc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) int rc, skb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) u8 *next, nfcid3[NFC_NFCID3_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) dev_dbg(dev->dev, "%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) if (!dev->gb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) dev->gb = nfc_get_local_general_bytes(nfc_dev, &dev->gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) if (!dev->gb || !dev->gb_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) dev->poll_dep = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) queue_work(dev->wq, &dev->rf_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) skb_len = 3 + dev->gb_len; /* ActPass + BR + Next */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) skb_len += PASSIVE_DATA_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) /* NFCID3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) skb_len += NFC_NFCID3_MAXSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) nfcid3[0] = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) nfcid3[1] = 0xfe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) get_random_bytes(nfcid3 + 2, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) skb = pn533_alloc_skb(dev, skb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) skb_put_u8(skb, 0x01); /* Active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) skb_put_u8(skb, 0x02); /* 424 kbps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) next = skb_put(skb, 1); /* Next */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) *next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) /* Copy passive data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) skb_put_data(skb, passive_data, PASSIVE_DATA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) *next |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) /* Copy NFCID3 (which is NFCID2 from SENSF_RES) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) skb_put_data(skb, nfcid3, NFC_NFCID3_MAXSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) *next |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) skb_put_data(skb, dev->gb, dev->gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) *next |= 4; /* We have some Gi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) rc = pn533_send_cmd_async(dev, PN533_CMD_IN_JUMP_FOR_DEP, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) pn533_poll_dep_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) static int pn533_autopoll_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) struct pn532_autopoll_resp *apr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) struct nfc_target nfc_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) u8 nbtg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (IS_ERR(resp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) rc = PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) nfc_err(dev->dev, "%s autopoll complete error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) if (rc == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) if (dev->poll_mod_count != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) goto stop_poll;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) } else if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) "Error %d when running autopoll\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) goto stop_poll;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) nbtg = resp->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) if ((nbtg > 2) || (nbtg <= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) apr = (struct pn532_autopoll_resp *)&resp->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) while (nbtg--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) memset(&nfc_tgt, 0, sizeof(struct nfc_target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) switch (apr->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) case PN532_AUTOPOLL_TYPE_ISOA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) dev_dbg(dev->dev, "ISOA\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) rc = pn533_target_found_type_a(&nfc_tgt, apr->tgdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) apr->ln - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) case PN532_AUTOPOLL_TYPE_FELICA212:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) case PN532_AUTOPOLL_TYPE_FELICA424:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) dev_dbg(dev->dev, "FELICA\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) rc = pn533_target_found_felica(&nfc_tgt, apr->tgdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) apr->ln - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) case PN532_AUTOPOLL_TYPE_JEWEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) dev_dbg(dev->dev, "JEWEL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) rc = pn533_target_found_jewel(&nfc_tgt, apr->tgdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) apr->ln - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) case PN532_AUTOPOLL_TYPE_ISOB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) dev_dbg(dev->dev, "ISOB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) rc = pn533_target_found_type_b(&nfc_tgt, apr->tgdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) apr->ln - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) case PN532_AUTOPOLL_TYPE_MIFARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) dev_dbg(dev->dev, "Mifare\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) rc = pn533_target_found_type_a(&nfc_tgt, apr->tgdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) apr->ln - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) "Unknown current poll modulation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) rc = -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) if (!(nfc_tgt.supported_protocols & dev->poll_protocols)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) "The Tg found doesn't have the desired protocol\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) rc = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) dev->tgt_available_prots = nfc_tgt.supported_protocols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) apr = (struct pn532_autopoll_resp *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) (apr->tgdata + (apr->ln - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) pn533_poll_reset_mod_list(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) nfc_targets_found(dev->nfc_dev, &nfc_tgt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) stop_poll:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) nfc_err(dev->dev, "autopoll operation has been stopped\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) pn533_poll_reset_mod_list(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) dev->poll_protocols = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) static int pn533_poll_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) struct pn533_poll_modulations *cur_mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) if (IS_ERR(resp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) rc = PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) nfc_err(dev->dev, "%s Poll complete error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) if (rc == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) if (dev->poll_mod_count != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) goto stop_poll;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) } else if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) "Error %d when running poll\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) goto stop_poll;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) if (cur_mod->len == 0) { /* Target mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) del_timer(&dev->listen_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) rc = pn533_init_target_complete(dev, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) /* Initiator mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) rc = pn533_start_poll_complete(dev, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) if (!dev->poll_mod_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) dev_dbg(dev->dev, "Polling has been stopped\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) pn533_poll_next_mod(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) /* Not target found, turn radio off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) queue_work(dev->wq, &dev->rf_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) stop_poll:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) nfc_err(dev->dev, "Polling operation has been stopped\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) pn533_poll_reset_mod_list(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) dev->poll_protocols = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) static struct sk_buff *pn533_alloc_poll_in_frame(struct pn533 *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) struct pn533_poll_modulations *mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) skb = pn533_alloc_skb(dev, mod->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) skb_put_data(skb, &mod->data, mod->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) static int pn533_send_poll_frame(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) struct pn533_poll_modulations *mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) u8 cmd_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) mod = dev->poll_mod_active[dev->poll_mod_curr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) dev_dbg(dev->dev, "%s mod len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) __func__, mod->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) if ((dev->poll_protocols & NFC_PROTO_NFC_DEP_MASK) && dev->poll_dep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) dev->poll_dep = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) return pn533_poll_dep(dev->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) if (mod->len == 0) { /* Listen mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) cmd_code = PN533_CMD_TG_INIT_AS_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) skb = pn533_alloc_poll_tg_frame(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) } else { /* Polling mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) cmd_code = PN533_CMD_IN_LIST_PASSIVE_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) skb = pn533_alloc_poll_in_frame(dev, mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) nfc_err(dev->dev, "Failed to allocate skb\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) rc = pn533_send_cmd_async(dev, cmd_code, skb, pn533_poll_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) nfc_err(dev->dev, "Polling loop error %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) static void pn533_wq_poll(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) struct pn533 *dev = container_of(work, struct pn533, poll_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) struct pn533_poll_modulations *cur_mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) dev_dbg(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) "%s cancel_listen %d modulation len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) __func__, dev->cancel_listen, cur_mod->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) if (dev->cancel_listen == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) dev->cancel_listen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) dev->phy_ops->abort_cmd(dev, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) rc = pn533_send_poll_frame(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) if (cur_mod->len == 0 && dev->poll_mod_count > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) mod_timer(&dev->listen_timer, jiffies + PN533_LISTEN_TIME * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) static int pn533_start_poll(struct nfc_dev *nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) u32 im_protocols, u32 tm_protocols)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) struct pn533_poll_modulations *cur_mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) u8 rand_mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) dev_dbg(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) "%s: im protocols 0x%x tm protocols 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) __func__, im_protocols, tm_protocols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (dev->tgt_active_prot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) "Cannot poll with a target already activated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) if (dev->tgt_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) "Cannot poll while already being activated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) if (tm_protocols) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) dev->gb = nfc_get_local_general_bytes(nfc_dev, &dev->gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) if (dev->gb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) tm_protocols = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) dev->poll_protocols = im_protocols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) dev->listen_protocols = tm_protocols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) if (dev->device_type == PN533_DEVICE_PN532_AUTOPOLL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) skb = pn533_alloc_skb(dev, 4 + 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) PN532_AUTOPOLL_POLLNR_INFINITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) *((u8 *)skb_put(skb, sizeof(u8))) = PN532_AUTOPOLL_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) if ((im_protocols & NFC_PROTO_MIFARE_MASK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) (im_protocols & NFC_PROTO_ISO14443_MASK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) (im_protocols & NFC_PROTO_NFC_DEP_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) PN532_AUTOPOLL_TYPE_GENERIC_106;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) if (im_protocols & NFC_PROTO_MIFARE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) PN532_AUTOPOLL_TYPE_MIFARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) if (im_protocols & NFC_PROTO_ISO14443_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) PN532_AUTOPOLL_TYPE_ISOA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) if (im_protocols & NFC_PROTO_NFC_DEP_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) PN532_AUTOPOLL_TYPE_DEP_PASSIVE_106;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) PN532_AUTOPOLL_TYPE_DEP_PASSIVE_212;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) PN532_AUTOPOLL_TYPE_DEP_PASSIVE_424;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) if (im_protocols & NFC_PROTO_FELICA_MASK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) im_protocols & NFC_PROTO_NFC_DEP_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) PN532_AUTOPOLL_TYPE_FELICA212;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) PN532_AUTOPOLL_TYPE_FELICA424;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) if (im_protocols & NFC_PROTO_JEWEL_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) PN532_AUTOPOLL_TYPE_JEWEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) if (im_protocols & NFC_PROTO_ISO14443_B_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) PN532_AUTOPOLL_TYPE_ISOB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) if (tm_protocols)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) *((u8 *)skb_put(skb, sizeof(u8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) PN532_AUTOPOLL_TYPE_DEP_ACTIVE_106;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) rc = pn533_send_cmd_async(dev, PN533_CMD_IN_AUTOPOLL, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) pn533_autopoll_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) dev->poll_mod_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) pn533_poll_create_mod_list(dev, im_protocols, tm_protocols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) /* Do not always start polling from the same modulation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) get_random_bytes(&rand_mod, sizeof(rand_mod));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) rand_mod %= dev->poll_mod_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) dev->poll_mod_curr = rand_mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) rc = pn533_send_poll_frame(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) /* Start listen timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) if (!rc && cur_mod->len == 0 && dev->poll_mod_count > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) mod_timer(&dev->listen_timer, jiffies + PN533_LISTEN_TIME * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) static void pn533_stop_poll(struct nfc_dev *nfc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) del_timer(&dev->listen_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) if (!dev->poll_mod_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) dev_dbg(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) "Polling operation was not running\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) dev->phy_ops->abort_cmd(dev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) flush_delayed_work(&dev->poll_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) pn533_poll_reset_mod_list(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) static int pn533_activate_target_nfcdep(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) struct pn533_cmd_activate_response *rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) u16 gt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) struct sk_buff *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) skb = pn533_alloc_skb(dev, sizeof(u8) * 2); /*TG + Next*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) skb_put_u8(skb, 1); /* TG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) skb_put_u8(skb, 0); /* Next */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) resp = pn533_send_cmd_sync(dev, PN533_CMD_IN_ATR, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) if (IS_ERR(resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) rsp = (struct pn533_cmd_activate_response *)resp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) rc = rsp->status & PN533_CMD_RET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) if (rc != PN533_CMD_RET_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) "Target activation failed (error 0x%x)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) /* ATR_RES general bytes are located at offset 16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) gt_len = resp->len - 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) rc = nfc_set_remote_general_bytes(dev->nfc_dev, rsp->gt, gt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) static int pn533_activate_target(struct nfc_dev *nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) struct nfc_target *target, u32 protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) dev_dbg(dev->dev, "%s: protocol=%u\n", __func__, protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) if (dev->poll_mod_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) "Cannot activate while polling\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) if (dev->tgt_active_prot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) "There is already an active target\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) if (!dev->tgt_available_prots) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) "There is no available target to activate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) if (!(dev->tgt_available_prots & (1 << protocol))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) "Target doesn't support requested proto %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) if (protocol == NFC_PROTO_NFC_DEP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) rc = pn533_activate_target_nfcdep(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) "Activating target with DEP failed %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) dev->tgt_active_prot = protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) dev->tgt_available_prots = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) static int pn533_deactivate_target_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) if (IS_ERR(resp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) rc = PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) nfc_err(dev->dev, "Target release error %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) rc = resp->data[0] & PN533_CMD_RET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) if (rc != PN533_CMD_RET_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) "Error 0x%x when releasing the target\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) static void pn533_deactivate_target(struct nfc_dev *nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) struct nfc_target *target, u8 mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) if (!dev->tgt_active_prot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) nfc_err(dev->dev, "There is no active target\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) dev->tgt_active_prot = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) skb_queue_purge(&dev->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) skb = pn533_alloc_skb(dev, sizeof(u8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) skb_put_u8(skb, 1); /* TG*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) rc = pn533_send_cmd_async(dev, PN533_CMD_IN_RELEASE, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) pn533_deactivate_target_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) nfc_err(dev->dev, "Target release error %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) struct pn533_cmd_jump_dep_response *rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) u8 target_gt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) u8 active = *(u8 *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) kfree(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) if (IS_ERR(resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) if (dev->tgt_available_prots &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) !(dev->tgt_available_prots & (1 << NFC_PROTO_NFC_DEP))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) "The target does not support DEP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) rsp = (struct pn533_cmd_jump_dep_response *)resp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) rc = rsp->status & PN533_CMD_RET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) if (rc != PN533_CMD_RET_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) "Bringing DEP link up failed (error 0x%x)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) if (!dev->tgt_available_prots) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) struct nfc_target nfc_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) dev_dbg(dev->dev, "Creating new target\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) nfc_target.nfcid1_len = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) memcpy(nfc_target.nfcid1, rsp->nfcid3t, nfc_target.nfcid1_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) rc = nfc_targets_found(dev->nfc_dev, &nfc_target, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) dev->tgt_available_prots = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) dev->tgt_active_prot = NFC_PROTO_NFC_DEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) /* ATR_RES general bytes are located at offset 17 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) target_gt_len = resp->len - 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) rc = nfc_set_remote_general_bytes(dev->nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) rsp->gt, target_gt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) rc = nfc_dep_link_is_up(dev->nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) dev->nfc_dev->targets[0].idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) !active, NFC_RF_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) static int pn533_rf_field(struct nfc_dev *nfc_dev, u8 rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) u8 comm_mode, u8 *gb, size_t gb_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) int rc, skb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) u8 *next, *arg, nfcid3[NFC_NFCID3_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) if (dev->poll_mod_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) "Cannot bring the DEP link up while polling\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (dev->tgt_active_prot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) "There is already an active target\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) skb_len = 3 + gb_len; /* ActPass + BR + Next */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) skb_len += PASSIVE_DATA_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) /* NFCID3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) skb_len += NFC_NFCID3_MAXSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) if (target && !target->nfcid2_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) nfcid3[0] = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) nfcid3[1] = 0xfe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) get_random_bytes(nfcid3 + 2, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) skb = pn533_alloc_skb(dev, skb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) skb_put_u8(skb, !comm_mode); /* ActPass */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) skb_put_u8(skb, 0x02); /* 424 kbps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) next = skb_put(skb, 1); /* Next */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) *next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) /* Copy passive data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) skb_put_data(skb, passive_data, PASSIVE_DATA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) *next |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) /* Copy NFCID3 (which is NFCID2 from SENSF_RES) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) if (target && target->nfcid2_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) memcpy(skb_put(skb, NFC_NFCID3_MAXSIZE), target->nfcid2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) target->nfcid2_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) skb_put_data(skb, nfcid3, NFC_NFCID3_MAXSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) *next |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) if (gb != NULL && gb_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) skb_put_data(skb, gb, gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) *next |= 4; /* We have some Gi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) *next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) arg = kmalloc(sizeof(*arg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) if (!arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) *arg = !comm_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) pn533_rf_field(dev->nfc_dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) rc = pn533_send_cmd_async(dev, PN533_CMD_IN_JUMP_FOR_DEP, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) pn533_in_dep_link_up_complete, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) kfree(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) static int pn533_dep_link_down(struct nfc_dev *nfc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) pn533_poll_reset_mod_list(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) if (dev->tgt_mode || dev->tgt_active_prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) dev->phy_ops->abort_cmd(dev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) dev->tgt_active_prot = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) dev->tgt_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) skb_queue_purge(&dev->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) struct pn533_data_exchange_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) data_exchange_cb_t cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) void *cb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) static struct sk_buff *pn533_build_response(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) struct sk_buff *skb, *tmp, *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) unsigned int skb_len = 0, tmp_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) if (skb_queue_empty(&dev->resp_q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) if (skb_queue_len(&dev->resp_q) == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) skb = skb_dequeue(&dev->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) skb_queue_walk_safe(&dev->resp_q, tmp, t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) skb_len += tmp->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) dev_dbg(dev->dev, "%s total length %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) __func__, skb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) skb = alloc_skb(skb_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) skb_put(skb, skb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) skb_queue_walk_safe(&dev->resp_q, tmp, t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) memcpy(skb->data + tmp_len, tmp->data, tmp->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) tmp_len += tmp->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) skb_queue_purge(&dev->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) struct pn533_data_exchange_arg *arg = _arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) u8 status, ret, mi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) if (IS_ERR(resp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) rc = PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) goto _error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) status = resp->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) ret = status & PN533_CMD_RET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) mi = status & PN533_CMD_MI_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) skb_pull(resp, sizeof(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) if (ret != PN533_CMD_RET_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) "Exchanging data failed (error 0x%x)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) skb_queue_tail(&dev->resp_q, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) if (mi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) dev->cmd_complete_mi_arg = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) queue_work(dev->wq, &dev->mi_rx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) return -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) /* Prepare for the next round */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) if (skb_queue_len(&dev->fragment_skb) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) dev->cmd_complete_dep_arg = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) queue_work(dev->wq, &dev->mi_tx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) return -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) skb = pn533_build_response(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) arg->cb(arg->cb_context, skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) kfree(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) _error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) skb_queue_purge(&dev->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) arg->cb(arg->cb_context, NULL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) kfree(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) * Receive an incoming pn533 frame. skb contains only header and payload.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) * If skb == NULL, it is a notification that the link below is dead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) void pn533_recv_frame(struct pn533 *dev, struct sk_buff *skb, int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) if (!dev->cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) goto sched_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) dev->cmd->status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) if (status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) dev_dbg(dev->dev, "%s: Error received: %d\n", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) goto sched_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) if (skb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) pr_err("NULL Frame -> link is dead\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) goto sched_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) if (pn533_rx_frame_is_ack(skb->data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) dev_dbg(dev->dev, "%s: Received ACK frame\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) print_hex_dump_debug("PN533 RX: ", DUMP_PREFIX_NONE, 16, 1, skb->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) dev->ops->rx_frame_size(skb->data), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) if (!dev->ops->rx_is_frame_valid(skb->data, dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) nfc_err(dev->dev, "Received an invalid frame\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) dev->cmd->status = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) } else if (!pn533_rx_frame_is_cmd_response(dev, skb->data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) nfc_err(dev->dev, "It it not the response to the last command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) dev->cmd->status = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) dev->cmd->resp = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) sched_wq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) queue_work(dev->wq, &dev->cmd_complete_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) EXPORT_SYMBOL(pn533_recv_frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) /* Split the Tx skb into small chunks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) static int pn533_fill_fragment_skbs(struct pn533 *dev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) struct sk_buff *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) int frag_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) /* Remaining size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) if (skb->len > PN533_CMD_DATAFRAME_MAXLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) frag_size = PN533_CMD_DATAFRAME_MAXLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) frag_size = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) /* Allocate and reserve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) frag = pn533_alloc_skb(dev, frag_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) if (!frag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) skb_queue_purge(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) if (!dev->tgt_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) /* Reserve the TG/MI byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) skb_reserve(frag, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) /* MI + TG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) if (frag_size == PN533_CMD_DATAFRAME_MAXLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) *(u8 *)skb_push(frag, sizeof(u8)) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) (PN533_CMD_MI_MASK | 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) *(u8 *)skb_push(frag, sizeof(u8)) = 1; /* TG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) skb_put_data(frag, skb->data, frag_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) /* Reduce the size of incoming buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) skb_pull(skb, frag_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) /* Add this to skb_queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) skb_queue_tail(&dev->fragment_skb, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) } while (skb->len > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) return skb_queue_len(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) static int pn533_transceive(struct nfc_dev *nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) struct nfc_target *target, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) data_exchange_cb_t cb, void *cb_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) struct pn533_data_exchange_arg *arg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) if (!dev->tgt_active_prot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) "Can't exchange data if there is no active target\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) arg = kmalloc(sizeof(*arg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) if (!arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) arg->cb = cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) arg->cb_context = cb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) switch (dev->device_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) case PN533_DEVICE_PASORI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) if (dev->tgt_active_prot == NFC_PROTO_FELICA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) rc = pn533_send_data_async(dev, PN533_CMD_IN_COMM_THRU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) pn533_data_exchange_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) /* jumbo frame ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) if (skb->len > PN533_CMD_DATAEXCH_DATA_MAXLEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) rc = pn533_fill_fragment_skbs(dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) skb = skb_dequeue(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) *(u8 *)skb_push(skb, sizeof(u8)) = 1; /* TG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) rc = pn533_send_data_async(dev, PN533_CMD_IN_DATA_EXCHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) skb, pn533_data_exchange_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) if (rc < 0) /* rc from send_async */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) kfree(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) static int pn533_tm_send_complete(struct pn533 *dev, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) struct sk_buff *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) if (IS_ERR(resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) status = resp->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) /* Prepare for the next round */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) if (skb_queue_len(&dev->fragment_skb) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) queue_work(dev->wq, &dev->mi_tm_tx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) return -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) if (status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) nfc_tm_deactivated(dev->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) dev->tgt_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) queue_work(dev->wq, &dev->tg_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) static int pn533_tm_send(struct nfc_dev *nfc_dev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) /* let's split in multiple chunks if size's too big */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) if (skb->len > PN533_CMD_DATAEXCH_DATA_MAXLEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) rc = pn533_fill_fragment_skbs(dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) /* get the first skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) skb = skb_dequeue(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) rc = pn533_send_data_async(dev, PN533_CMD_TG_SET_META_DATA, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) pn533_tm_send_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) /* Send th skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) rc = pn533_send_data_async(dev, PN533_CMD_TG_SET_DATA, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) pn533_tm_send_complete, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) skb_queue_purge(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) static void pn533_wq_mi_recv(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) struct pn533 *dev = container_of(work, struct pn533, mi_rx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) skb = pn533_alloc_skb(dev, PN533_CMD_DATAEXCH_HEAD_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) switch (dev->device_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) case PN533_DEVICE_PASORI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) if (dev->tgt_active_prot == NFC_PROTO_FELICA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) rc = pn533_send_cmd_direct_async(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) PN533_CMD_IN_COMM_THRU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) pn533_data_exchange_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) dev->cmd_complete_mi_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) skb_put_u8(skb, 1); /*TG*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) rc = pn533_send_cmd_direct_async(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) PN533_CMD_IN_DATA_EXCHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) pn533_data_exchange_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) dev->cmd_complete_mi_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) if (rc == 0) /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) "Error %d when trying to perform data_exchange\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) kfree(dev->cmd_complete_mi_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) dev->phy_ops->send_ack(dev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) queue_work(dev->wq, &dev->cmd_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) static void pn533_wq_mi_send(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) struct pn533 *dev = container_of(work, struct pn533, mi_tx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) /* Grab the first skb in the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) skb = skb_dequeue(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) if (skb == NULL) { /* No more data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) /* Reset the queue for future use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) skb_queue_head_init(&dev->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) switch (dev->device_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) case PN533_DEVICE_PASORI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) if (dev->tgt_active_prot != NFC_PROTO_FELICA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) rc = pn533_send_cmd_direct_async(dev, PN533_CMD_IN_COMM_THRU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) pn533_data_exchange_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) dev->cmd_complete_dep_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) /* Still some fragments? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) rc = pn533_send_cmd_direct_async(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) PN533_CMD_IN_DATA_EXCHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) pn533_data_exchange_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) dev->cmd_complete_dep_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) if (rc == 0) /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) "Error %d when trying to perform data_exchange\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) kfree(dev->cmd_complete_dep_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) dev->phy_ops->send_ack(dev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) queue_work(dev->wq, &dev->cmd_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) u8 cfgdata_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) struct sk_buff *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) int skb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) skb_len = sizeof(cfgitem) + cfgdata_len; /* cfgitem + cfgdata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) skb = pn533_alloc_skb(dev, skb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) skb_put_u8(skb, cfgitem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) skb_put_data(skb, cfgdata, cfgdata_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) resp = pn533_send_cmd_sync(dev, PN533_CMD_RF_CONFIGURATION, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) if (IS_ERR(resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) static int pn533_get_firmware_version(struct pn533 *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) struct pn533_fw_version *fv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) struct sk_buff *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) skb = pn533_alloc_skb(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) resp = pn533_send_cmd_sync(dev, PN533_CMD_GET_FIRMWARE_VERSION, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) if (IS_ERR(resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) fv->ic = resp->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) fv->ver = resp->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) fv->rev = resp->data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) fv->support = resp->data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) static int pn533_pasori_fw_reset(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) struct sk_buff *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) skb = pn533_alloc_skb(dev, sizeof(u8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) skb_put_u8(skb, 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) resp = pn533_send_cmd_sync(dev, 0x18, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) if (IS_ERR(resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) static int pn533_rf_field(struct nfc_dev *nfc_dev, u8 rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) u8 rf_field = !!rf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) rf_field |= PN533_CFGITEM_RF_FIELD_AUTO_RFCA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) rc = pn533_set_configuration(dev, PN533_CFGITEM_RF_FIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) (u8 *)&rf_field, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) nfc_err(dev->dev, "Error on setting RF field\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) static int pn532_sam_configuration(struct nfc_dev *nfc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) struct sk_buff *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) skb = pn533_alloc_skb(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) skb_put_u8(skb, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) resp = pn533_send_cmd_sync(dev, PN533_CMD_SAM_CONFIGURATION, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) if (IS_ERR(resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) return PTR_ERR(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) dev_kfree_skb(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) static int pn533_dev_up(struct nfc_dev *nfc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) if (dev->phy_ops->dev_up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) rc = dev->phy_ops->dev_up(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) if ((dev->device_type == PN533_DEVICE_PN532) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) (dev->device_type == PN533_DEVICE_PN532_AUTOPOLL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) rc = pn532_sam_configuration(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) return pn533_rf_field(nfc_dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) static int pn533_dev_down(struct nfc_dev *nfc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) struct pn533 *dev = nfc_get_drvdata(nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) ret = pn533_rf_field(nfc_dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) if (dev->phy_ops->dev_down && !ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) ret = dev->phy_ops->dev_down(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) static struct nfc_ops pn533_nfc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) .dev_up = pn533_dev_up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) .dev_down = pn533_dev_down,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) .dep_link_up = pn533_dep_link_up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) .dep_link_down = pn533_dep_link_down,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) .start_poll = pn533_start_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) .stop_poll = pn533_stop_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) .activate_target = pn533_activate_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) .deactivate_target = pn533_deactivate_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) .im_transceive = pn533_transceive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) .tm_send = pn533_tm_send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) static int pn533_setup(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) struct pn533_config_max_retries max_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) struct pn533_config_timing timing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) u8 pasori_cfg[3] = {0x08, 0x01, 0x08};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) switch (dev->device_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) case PN533_DEVICE_STD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) case PN533_DEVICE_PASORI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) case PN533_DEVICE_ACR122U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) case PN533_DEVICE_PN532:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) case PN533_DEVICE_PN532_AUTOPOLL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) max_retries.mx_rty_atr = 0x2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) max_retries.mx_rty_psl = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) max_retries.mx_rty_passive_act =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) PN533_CONFIG_MAX_RETRIES_NO_RETRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) timing.rfu = PN533_CONFIG_TIMING_102;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) timing.atr_res_timeout = PN533_CONFIG_TIMING_102;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) timing.dep_timeout = PN533_CONFIG_TIMING_204;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) nfc_err(dev->dev, "Unknown device type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) dev->device_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) rc = pn533_set_configuration(dev, PN533_CFGITEM_MAX_RETRIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) (u8 *)&max_retries, sizeof(max_retries));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) "Error on setting MAX_RETRIES config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) rc = pn533_set_configuration(dev, PN533_CFGITEM_TIMING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) (u8 *)&timing, sizeof(timing));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) nfc_err(dev->dev, "Error on setting RF timings\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) switch (dev->device_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) case PN533_DEVICE_STD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) case PN533_DEVICE_PN532:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) case PN533_DEVICE_PN532_AUTOPOLL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) case PN533_DEVICE_PASORI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) pn533_pasori_fw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) rc = pn533_set_configuration(dev, PN533_CFGITEM_PASORI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) pasori_cfg, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) nfc_err(dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) "Error while settings PASORI config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) pn533_pasori_fw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) int pn533_finalize_setup(struct pn533 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) struct pn533_fw_version fw_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) memset(&fw_ver, 0, sizeof(fw_ver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) rc = pn533_get_firmware_version(dev, &fw_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) nfc_err(dev->dev, "Unable to get FW version\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) nfc_info(dev->dev, "NXP PN5%02X firmware ver %d.%d now attached\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) fw_ver.ic, fw_ver.ver, fw_ver.rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) rc = pn533_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) EXPORT_SYMBOL_GPL(pn533_finalize_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) struct pn533 *pn53x_common_init(u32 device_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) enum pn533_protocol_type protocol_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) void *phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) struct pn533_phy_ops *phy_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) struct pn533_frame_ops *fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) struct pn533 *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) int rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) priv = kzalloc(sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) priv->phy = phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) priv->phy_ops = phy_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) priv->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) if (fops != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) priv->ops = fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) priv->ops = &pn533_std_frame_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) priv->protocol_type = protocol_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) priv->device_type = device_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) mutex_init(&priv->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) INIT_WORK(&priv->cmd_work, pn533_wq_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) INIT_WORK(&priv->cmd_complete_work, pn533_wq_cmd_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) INIT_WORK(&priv->mi_rx_work, pn533_wq_mi_recv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) INIT_WORK(&priv->mi_tx_work, pn533_wq_mi_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) INIT_WORK(&priv->tg_work, pn533_wq_tg_get_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) INIT_WORK(&priv->mi_tm_rx_work, pn533_wq_tm_mi_recv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) INIT_WORK(&priv->mi_tm_tx_work, pn533_wq_tm_mi_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) INIT_DELAYED_WORK(&priv->poll_work, pn533_wq_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) INIT_WORK(&priv->rf_work, pn533_wq_rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) priv->wq = alloc_ordered_workqueue("pn533", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) if (priv->wq == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) timer_setup(&priv->listen_timer, pn533_listen_mode_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) skb_queue_head_init(&priv->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) skb_queue_head_init(&priv->fragment_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) INIT_LIST_HEAD(&priv->cmd_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) return priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) EXPORT_SYMBOL_GPL(pn53x_common_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) void pn53x_common_clean(struct pn533 *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) struct pn533_cmd *cmd, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) flush_delayed_work(&priv->poll_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) destroy_workqueue(priv->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) skb_queue_purge(&priv->resp_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) del_timer(&priv->listen_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) list_for_each_entry_safe(cmd, n, &priv->cmd_queue, queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) list_del(&cmd->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) EXPORT_SYMBOL_GPL(pn53x_common_clean);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) int pn532_i2c_nfc_alloc(struct pn533 *priv, u32 protocols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) struct device *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) priv->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) priv->ops->tx_header_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) PN533_CMD_DATAEXCH_HEAD_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) priv->ops->tx_tail_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) if (!priv->nfc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) nfc_set_parent_dev(priv->nfc_dev, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) nfc_set_drvdata(priv->nfc_dev, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) EXPORT_SYMBOL_GPL(pn532_i2c_nfc_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) int pn53x_register_nfc(struct pn533 *priv, u32 protocols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) struct device *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) rc = pn532_i2c_nfc_alloc(priv, protocols, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) rc = nfc_register_device(priv->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) nfc_free_device(priv->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) EXPORT_SYMBOL_GPL(pn53x_register_nfc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) void pn53x_unregister_nfc(struct pn533 *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) nfc_unregister_device(priv->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) nfc_free_device(priv->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) EXPORT_SYMBOL_GPL(pn53x_unregister_nfc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) MODULE_AUTHOR("Lauro Ramos Venancio <lauro.venancio@openbossa.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) MODULE_AUTHOR("Aloisio Almeida Jr <aloisio.almeida@openbossa.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) MODULE_AUTHOR("Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) MODULE_DESCRIPTION("PN533 driver ver " VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) MODULE_VERSION(VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) MODULE_LICENSE("GPL");