summaryrefslogtreecommitdiffstats
path: root/packaging/makeself
AgeCommit message (Expand)Author
2024-01-30Network Viewer (local-sockets version) (#16872)Costa Tsaousis
2024-01-29Add ARMv6 static builds. (#16853)Austin S. Hemmelgarn
2024-01-17CI runtime check cleanup (#16713)Austin S. Hemmelgarn
2024-01-11packaging: add cap_dac_read_search to go.d.plugin (#16754)Ilya Mashchenko
2023-12-29add --disable-logsmanagement when building static (#16684)Ilya Mashchenko
2023-12-15ndsudo - a helper to run privileged commands (#16614)Costa Tsaousis
2023-11-22New logging layer (#16357)Costa Tsaousis
2023-11-07fix zstd in static build (#16349)Ilya Mashchenko
2023-11-06Update packaging instructions (#16344)Tasos Katsoulas
2023-10-30bump openssl for static in 3.1.4 (#16303)Tasos Katsoulas
2023-10-20Introduce workflow to always update bundled packages (static builds) into the...Tasos Katsoulas
2023-10-13Update bundled static packages (#16177)Tasos Katsoulas
2023-09-27Update to use versioned base images for CI. (#16053)Austin S. Hemmelgarn
2023-09-22Disable mongodb exporter builds where broken. (#16033)Austin S. Hemmelgarn
2023-08-21packaging cleanup after #15842 (#15857)Ilya Mashchenko
2023-08-21fix packaging static build openssl 32bit (#15855)Ilya Mashchenko
2023-08-21Fix static build SSL (#15842)Costa Tsaousis
2023-08-14Bump openssl version of static builds to 1.1.1v (#15779)Tasos Katsoulas
2023-08-09fix claiming via UI for static build (#15774)Ilya Mashchenko
2023-07-18Build optimizations (#15381)Tasos Katsoulas
2023-07-06Code reorg and cleanup - enrichment of /api/v2 (#15294)Costa Tsaousis
2023-06-28Add hardening options to CFLAGS by default if they are available. (#15087)Austin S. Hemmelgarn
2023-06-22Fix handling of plugin ownership in static builds. (#15230)Austin S. Hemmelgarn
2023-05-15Debugfs collector (#15017)thiagoftsm
2023-05-11Fix handling of permissions in static installs. (#15042)Austin S. Hemmelgarn
2023-05-11Remove old logic for handling of legacy stock config files. (#14829)Austin S. Hemmelgarn
2023-05-07Fix typo in file capabilities settings in static installer. (#15023)Austin S. Hemmelgarn
2023-05-05Set file capabilities correctly on static installs. (#15018)Austin S. Hemmelgarn
2023-04-25Prevent pager from preventing non-interactive install (#14950)Aaron Queen
2023-04-12Update the bundled version of makeself used to create static builds. (#14822)Austin S. Hemmelgarn
2023-03-23Fix handling of logrotate on static installs. (#14792)Austin S. Hemmelgarn
2023-03-01Link statically libnetfilter_acct into our static builds (#14516)Tasos Katsoulas
2023-02-28Make the title metadata H1 in all markdown files (#14625)Fotis Voutsas
2023-02-27Reorganize system directory to better reflect what files are actually used fo...Austin S. Hemmelgarn
2023-02-21Learn installation reorg part 2 (#14579)Chris Akritidis
2023-02-21Update static binary readme (#14574)Chris Akritidis
2023-02-16Assorted shellcheck cleanup. (#14524)Austin S. Hemmelgarn
2023-02-08Add markdown files in Learn (#14466)Fotis Voutsas
2023-02-08Update static build packages (#14450)Tasos Katsoulas
2023-01-25Assorted infrastructure cleanup. (#14223)Austin S. Hemmelgarn
2023-01-04Finish renaming the `--install` option to `--install-prefix`. (#13881)Austin S. Hemmelgarn
2022-12-22feat(packaging): add netdata to www-data group on Proxmox (#14168)Ilya Mashchenko
2022-12-09remove deprecated fping.plugin in accordance with v1.37.0 deprecation notice ...Ilya Mashchenko
2022-10-31feat(packaging): add CAP_NET_RAW to go.d.plugin (#13909)Ilya Mashchenko
2022-08-11fix(packaging): add CAP_NET_ADMIN for go.d.plugin (#13507)Ilya Mashchenko
2022-07-14Add basic runtime checks to static build process. (#13339)Austin S. Hemmelgarn
2022-06-09Remove unnescesary ‘cleanup’ code. (#13103)Austin S. Hemmelgarn
2022-05-27Cache invariant components in static builds to reduce build times. (#12877)Austin S. Hemmelgarn
2022-05-10Use prebuilt builder images for static builds. (#12826)Austin S. Hemmelgarn
2022-05-02Add `-pipe` to CFLAGS in most cases for builds. (#12709)Austin S. Hemmelgarn
'#n485'>485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
/*
 * NFC hardware simulation driver
 * Copyright (c) 2013, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 */

#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/debugfs.h>
#include <linux/nfc.h>
#include <net/nfc/nfc.h>
#include <net/nfc/digital.h>

#define NFCSIM_ERR(d, fmt, args...) nfc_err(&d->nfc_digital_dev->nfc_dev->dev, \
					    "%s: " fmt, __func__, ## args)

#define NFCSIM_DBG(d, fmt, args...) dev_dbg(&d->nfc_digital_dev->nfc_dev->dev, \
					    "%s: " fmt, __func__, ## args)

#define NFCSIM_VERSION "0.2"

#define NFCSIM_MODE_NONE	0
#define NFCSIM_MODE_INITIATOR	1
#define NFCSIM_MODE_TARGET	2

#define NFCSIM_CAPABILITIES (NFC_DIGITAL_DRV_CAPS_IN_CRC   | \
			     NFC_DIGITAL_DRV_CAPS_TG_CRC)

struct nfcsim {
	struct nfc_digital_dev *nfc_digital_dev;

	struct work_struct recv_work;
	struct delayed_work send_work;

	struct nfcsim_link *link_in;
	struct nfcsim_link *link_out;

	bool up;
	u8 mode;
	u8 rf_tech;

	u16 recv_timeout;

	nfc_digital_cmd_complete_t cb;
	void *arg;

	u8 dropframe;
};

struct nfcsim_link {
	struct mutex lock;

	u8 rf_tech;
	u8 mode;

	u8 shutdown;

	struct sk_buff *skb;
	wait_queue_head_t recv_wait;
	u8 cond;
};

static struct nfcsim_link *nfcsim_link_new(void)
{
	struct nfcsim_link *link;

	link = kzalloc(sizeof(struct nfcsim_link), GFP_KERNEL);
	if (!link)
		return NULL;

	mutex_init(&link->lock);
	init_waitqueue_head(&link->recv_wait);

	return link;
}

static void nfcsim_link_free(struct nfcsim_link *link)
{
	dev_kfree_skb(link->skb);
	kfree(link);
}

static void nfcsim_link_recv_wake(struct nfcsim_link *link)
{
	link->cond = 1;
	wake_up_interruptible(&link->recv_wait);
}

static void nfcsim_link_set_skb(struct nfcsim_link *link, struct sk_buff *skb,
				u8 rf_tech, u8 mode)
{
	mutex_lock(&link->lock);

	dev_kfree_skb(link->skb);
	link->skb = skb;
	link->rf_tech = rf_tech;
	link->mode = mode;

	mutex_unlock(&link->lock);
}

static void nfcsim_link_recv_cancel(struct nfcsim_link *link)
{
	mutex_lock(&link->lock);

	link->mode = NFCSIM_MODE_NONE;

	mutex_unlock(&link->lock);

	nfcsim_link_recv_wake(link);
}

static void nfcsim_link_shutdown(struct nfcsim_link *link)
{
	mutex_lock(&link->lock);

	link->shutdown = 1;
	link->mode = NFCSIM_MODE_NONE;

	mutex_unlock(&link->lock);

	nfcsim_link_recv_wake(link);
}

static struct sk_buff *nfcsim_link_recv_skb(struct nfcsim_link *link,
					    int timeout, u8 rf_tech, u8 mode)
{
	int rc;
	struct sk_buff *skb;

	rc = wait_event_interruptible_timeout(link->recv_wait,
					      link->cond,
					      msecs_to_jiffies(timeout));

	mutex_lock(&link->lock);

	skb = link->skb;
	link->skb = NULL;

	if (!rc) {
		rc = -ETIMEDOUT;
		goto done;
	}

	if (!skb || link->rf_tech != rf_tech || link->mode == mode) {
		rc = -EINVAL;
		goto done;
	}

	if (link->shutdown) {
		rc = -ENODEV;
		goto done;
	}

done:
	mutex_unlock(&link->lock);

	if (rc < 0) {
		dev_kfree_skb(skb);
		skb = ERR_PTR(rc);
	}

	link->cond = 0;

	return skb;
}

static void nfcsim_send_wq(struct work_struct *work)
{
	struct nfcsim *dev = container_of(work, struct nfcsim, send_work.work);

	/*
	 * To effectively send data, the device just wake up its link_out which
	 * is the link_in of the peer device. The exchanged skb has already been
	 * stored in the dev->link_out through nfcsim_link_set_skb().
	 */
	nfcsim_link_recv_wake(dev->link_out);
}

static void nfcsim_recv_wq(struct work_struct *work)
{
	struct nfcsim *dev = container_of(work, struct nfcsim, recv_work);
	struct sk_buff *skb;

	skb = nfcsim_link_recv_skb(dev->link_in, dev->recv_timeout,
				   dev->rf_tech, dev->mode);

	if (!dev->up) {
		NFCSIM_ERR(dev, "Device is down\n");

		if (!IS_ERR(skb))
			dev_kfree_skb(skb);

		skb = ERR_PTR(-ENODEV);
	}

	dev->cb(dev->nfc_digital_dev, dev->arg, skb);
}

static int nfcsim_send(struct nfc_digital_dev *ddev, struct sk_buff *skb,
		       u16 timeout, nfc_digital_cmd_complete_t cb, void *arg)
{
	struct nfcsim *dev = nfc_digital_get_drvdata(ddev);
	u8 delay;

	if (!dev->up) {
		NFCSIM_ERR(dev, "Device is down\n");
		return -ENODEV;
	}

	dev->recv_timeout = timeout;
	dev->cb = cb;
	dev->arg = arg;

	schedule_work(&dev->recv_work);

	if (dev->dropframe) {
		NFCSIM_DBG(dev, "dropping frame (out of %d)\n", dev->dropframe);
		dev_kfree_skb(skb);
		dev->dropframe--;

		return 0;
	}

	if (skb) {
		nfcsim_link_set_skb(dev->link_out, skb, dev->rf_tech,
				    dev->mode);

		/* Add random delay (between 3 and 10 ms) before sending data */
		get_random_bytes(&delay, 1);
		delay = 3 + (delay & 0x07);

		schedule_delayed_work(&dev->send_work, msecs_to_jiffies(delay));
	}

	return 0;
}

static void nfcsim_abort_cmd(struct nfc_digital_dev *ddev)
{
	struct nfcsim *dev = nfc_digital_get_drvdata(ddev);

	nfcsim_link_recv_cancel(dev->link_in);
}

static int nfcsim_switch_rf(struct nfc_digital_dev *ddev, bool on)
{
	struct nfcsim *dev = nfc_digital_get_drvdata(ddev);

	dev->up = on;

	return 0;
}

static int nfcsim_in_configure_hw(struct nfc_digital_dev *ddev,
					  int type, int param)
{
	struct nfcsim *dev = nfc_digital_get_drvdata(ddev);

	switch (type) {
	case NFC_DIGITAL_CONFIG_RF_TECH:
		dev->up = true;
		dev->mode = NFCSIM_MODE_INITIATOR;
		dev->rf_tech = param;
		break;

	case NFC_DIGITAL_CONFIG_FRAMING:
		break;

	default:
		NFCSIM_ERR(dev, "Invalid configuration type: %d\n", type);
		return -EINVAL;
	}

	return 0;
}

static int nfcsim_in_send_cmd(struct nfc_digital_dev *ddev,
			       struct sk_buff *skb, u16 timeout,
			       nfc_digital_cmd_complete_t cb, void *arg)
{
	return nfcsim_send(ddev, skb, timeout, cb, arg);
}

static int nfcsim_tg_configure_hw(struct nfc_digital_dev *ddev,
					  int type, int param)
{
	struc