Skip to content

Commit f212ad5

Browse files
author
Samuel Ortiz
committed
NFC: Set the NFC device RF mode appropriately
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent fc40a8c commit f212ad5

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎include/linux/nfc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ enum nfc_attrs {
146146
/* NFC RF modes */
147147
#define NFC_RF_INITIATOR 0
148148
#define NFC_RF_TARGET 1
149+
#define NFC_RF_NONE 2
149150

150151
/* NFC protocols masks used in bitsets */
151152
#define NFC_PROTO_JEWEL_MASK (1 << NFC_PROTO_JEWEL)

‎include/net/nfc/nfc.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ struct nfc_dev {
100100
int targets_generation;
101101
struct device dev;
102102
bool dev_up;
103+
u8 rf_mode;
103104
bool polling;
104105
struct nfc_target *active_target;
105106
bool dep_link_up;
106-
u32 dep_rf_mode;
107107
struct nfc_genl_data genl_data;
108108
u32 supported_protocols;
109109

‎net/nfc/core.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols)
144144
}
145145

146146
rc = dev->ops->start_poll(dev, im_protocols, tm_protocols);
147-
if (!rc)
147+
if (!rc) {
148148
dev->polling = true;
149+
dev->rf_mode = NFC_RF_NONE;
150+
}
149151

150152
error:
151153
device_unlock(&dev->dev);
@@ -235,8 +237,10 @@ int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
235237
}
236238

237239
rc = dev->ops->dep_link_up(dev, target, comm_mode, gb, gb_len);
238-
if (!rc)
240+
if (!rc) {
239241
dev->active_target = target;
242+
dev->rf_mode = NFC_RF_INITIATOR;
243+
}
240244

241245
error:
242246
device_unlock(&dev->dev);
@@ -264,7 +268,7 @@ int nfc_dep_link_down(struct nfc_dev *dev)
264268
goto error;
265269
}
266270

267-
if (dev->dep_rf_mode == NFC_RF_TARGET) {
271+
if (dev->rf_mode == NFC_RF_TARGET) {
268272
rc = -EOPNOTSUPP;
269273
goto error;
270274
}
@@ -286,7 +290,6 @@ int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
286290
u8 comm_mode, u8 rf_mode)
287291
{
288292
dev->dep_link_up = true;
289-
dev->dep_rf_mode = rf_mode;
290293

291294
nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode);
292295

@@ -330,6 +333,7 @@ int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
330333
rc = dev->ops->activate_target(dev, target, protocol);
331334
if (!rc) {
332335
dev->active_target = target;
336+
dev->rf_mode = NFC_RF_INITIATOR;
333337

334338
if (dev->ops->check_presence)
335339
mod_timer(&dev->check_pres_timer, jiffies +
@@ -470,6 +474,8 @@ int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
470474
goto out;
471475
}
472476

477+
dev->rf_mode = NFC_RF_TARGET;
478+
473479
if (protocol == NFC_PROTO_NFC_DEP_MASK)
474480
nfc_dep_link_is_up(dev, 0, comm_mode, NFC_RF_TARGET);
475481

0 commit comments

Comments
 (0)