net/bluetooth/selftest.c

Source file repositories/reference/linux-study-clean/net/bluetooth/selftest.c

File Facts

System
Linux kernel
Corpus path
net/bluetooth/selftest.c
Extension
.c
Size
8560 bytes
Lines
307
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations test_ecdh_fops = {
	.open		= simple_open,
	.read		= test_ecdh_read,
	.llseek		= default_llseek,
};

static int __init test_ecdh(void)
{
	struct crypto_kpp *tfm;
	ktime_t calltime, delta, rettime;
	unsigned long long duration = 0;
	int err;

	calltime = ktime_get();

	tfm = crypto_alloc_kpp("ecdh-nist-p256", 0, 0);
	if (IS_ERR(tfm)) {
		BT_ERR("Unable to create ECDH crypto context");
		err = PTR_ERR(tfm);
		goto done;
	}

	err = test_ecdh_sample(tfm, priv_a_1, priv_b_1, pub_a_1, pub_b_1,
			       dhkey_1);
	if (err) {
		BT_ERR("ECDH sample 1 failed");
		goto done;
	}

	err = test_ecdh_sample(tfm, priv_a_2, priv_b_2, pub_a_2, pub_b_2,
			       dhkey_2);
	if (err) {
		BT_ERR("ECDH sample 2 failed");
		goto done;
	}

	err = test_ecdh_sample(tfm, priv_a_3, priv_a_3, pub_a_3, pub_a_3,
			       dhkey_3);
	if (err) {
		BT_ERR("ECDH sample 3 failed");
		goto done;
	}

	crypto_free_kpp(tfm);

	rettime = ktime_get();
	delta = ktime_sub(rettime, calltime);
	duration = (unsigned long long) ktime_to_ns(delta) >> 10;

	BT_INFO("ECDH test passed in %llu usecs", duration);

done:
	if (!err)
		snprintf(test_ecdh_buffer, sizeof(test_ecdh_buffer),
			 "PASS (%llu usecs)\n", duration);
	else
		snprintf(test_ecdh_buffer, sizeof(test_ecdh_buffer), "FAIL\n");

	debugfs_create_file("selftest_ecdh", 0444, bt_debugfs, NULL,
			    &test_ecdh_fops);

	return err;
}

#else

static inline int test_ecdh(void)
{
	return 0;
}

#endif

static int __init run_selftest(void)
{
	int err;

	BT_INFO("Starting self testing");

	err = test_ecdh();
	if (err)
		goto done;

	err = bt_selftest_smp();

done:
	BT_INFO("Finished self testing");

	return err;
}

Annotation

Implementation Notes