Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 144612ca authored by Eric Lapuyade's avatar Eric Lapuyade Committed by John W. Linville
Browse files

NFC: Changed target activated state logic

parent 01ae0eea
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -66,6 +66,7 @@ struct nfc_ops {


#define NFC_TARGET_IDX_ANY -1
#define NFC_TARGET_IDX_ANY -1
#define NFC_MAX_GT_LEN 48
#define NFC_MAX_GT_LEN 48
#define NFC_TARGET_IDX_NONE 0xffffffff


struct nfc_target {
struct nfc_target {
	u32 idx;
	u32 idx;
@@ -97,7 +98,7 @@ struct nfc_dev {
	struct device dev;
	struct device dev;
	bool dev_up;
	bool dev_up;
	bool polling;
	bool polling;
	bool remote_activated;
	u32 activated_target_idx;
	bool dep_link_up;
	bool dep_link_up;
	u32 dep_rf_mode;
	u32 dep_rf_mode;
	struct nfc_genl_data genl_data;
	struct nfc_genl_data genl_data;
+21 −3
Original line number Original line Diff line number Diff line
@@ -95,7 +95,7 @@ int nfc_dev_down(struct nfc_dev *dev)
		goto error;
		goto error;
	}
	}


	if (dev->polling || dev->remote_activated) {
	if (dev->polling || dev->activated_target_idx != NFC_TARGET_IDX_NONE) {
		rc = -EBUSY;
		rc = -EBUSY;
		goto error;
		goto error;
	}
	}
@@ -211,6 +211,8 @@ int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
	}
	}


	rc = dev->ops->dep_link_up(dev, target_index, comm_mode, gb, gb_len);
	rc = dev->ops->dep_link_up(dev, target_index, comm_mode, gb, gb_len);
	if (!rc)
		dev->activated_target_idx = target_index;


error:
error:
	device_unlock(&dev->dev);
	device_unlock(&dev->dev);
@@ -246,6 +248,7 @@ int nfc_dep_link_down(struct nfc_dev *dev)
	rc = dev->ops->dep_link_down(dev);
	rc = dev->ops->dep_link_down(dev);
	if (!rc) {
	if (!rc) {
		dev->dep_link_up = false;
		dev->dep_link_up = false;
		dev->activated_target_idx = NFC_TARGET_IDX_NONE;
		nfc_llcp_mac_is_down(dev);
		nfc_llcp_mac_is_down(dev);
		nfc_genl_dep_link_down_event(dev);
		nfc_genl_dep_link_down_event(dev);
	}
	}
@@ -290,7 +293,7 @@ int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)


	rc = dev->ops->activate_target(dev, target_idx, protocol);
	rc = dev->ops->activate_target(dev, target_idx, protocol);
	if (!rc)
	if (!rc)
		dev->remote_activated = true;
		dev->activated_target_idx = target_idx;


error:
error:
	device_unlock(&dev->dev);
	device_unlock(&dev->dev);
@@ -318,7 +321,7 @@ int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
	}
	}


	dev->ops->deactivate_target(dev, target_idx);
	dev->ops->deactivate_target(dev, target_idx);
	dev->remote_activated = false;
	dev->activated_target_idx = NFC_TARGET_IDX_NONE;


error:
error:
	device_unlock(&dev->dev);
	device_unlock(&dev->dev);
@@ -352,6 +355,18 @@ int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
		goto error;
		goto error;
	}
	}


	if (dev->activated_target_idx == NFC_TARGET_IDX_NONE) {
		rc = -ENOTCONN;
		kfree_skb(skb);
		goto error;
	}

	if (target_idx != dev->activated_target_idx) {
		rc = -EADDRNOTAVAIL;
		kfree_skb(skb);
		goto error;
	}

	rc = dev->ops->data_exchange(dev, target_idx, skb, cb, cb_context);
	rc = dev->ops->data_exchange(dev, target_idx, skb, cb, cb_context);


error:
error:
@@ -482,6 +497,7 @@ int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)


	dev->targets_generation++;
	dev->targets_generation++;
	dev->n_targets--;
	dev->n_targets--;
	dev->activated_target_idx = NFC_TARGET_IDX_NONE;


	if (dev->n_targets) {
	if (dev->n_targets) {
		memcpy(&dev->targets[i], &dev->targets[i + 1],
		memcpy(&dev->targets[i], &dev->targets[i + 1],
@@ -575,6 +591,8 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
	/* first generation must not be 0 */
	/* first generation must not be 0 */
	dev->targets_generation = 1;
	dev->targets_generation = 1;


	dev->activated_target_idx = NFC_TARGET_IDX_NONE;

	return dev;
	return dev;
}
}
EXPORT_SYMBOL(nfc_allocate_device);
EXPORT_SYMBOL(nfc_allocate_device);