xref: /OK3568_Linux_fs/kernel/net/bluetooth/selftest.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun    BlueZ - Bluetooth protocol stack for Linux
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun    Copyright (C) 2014 Intel Corporation
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun    This program is free software; you can redistribute it and/or modify
7*4882a593Smuzhiyun    it under the terms of the GNU General Public License version 2 as
8*4882a593Smuzhiyun    published by the Free Software Foundation;
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
11*4882a593Smuzhiyun    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*4882a593Smuzhiyun    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
13*4882a593Smuzhiyun    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
14*4882a593Smuzhiyun    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
15*4882a593Smuzhiyun    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16*4882a593Smuzhiyun    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17*4882a593Smuzhiyun    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
20*4882a593Smuzhiyun    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
21*4882a593Smuzhiyun    SOFTWARE IS DISCLAIMED.
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #include <linux/debugfs.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #include <net/bluetooth/bluetooth.h>
27*4882a593Smuzhiyun #include <net/bluetooth/hci_core.h>
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #include "ecdh_helper.h"
30*4882a593Smuzhiyun #include "smp.h"
31*4882a593Smuzhiyun #include "selftest.h"
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_BT_SELFTEST_ECDH)
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun static const u8 priv_a_1[32] __initconst = {
36*4882a593Smuzhiyun 	0xbd, 0x1a, 0x3c, 0xcd, 0xa6, 0xb8, 0x99, 0x58,
37*4882a593Smuzhiyun 	0x99, 0xb7, 0x40, 0xeb, 0x7b, 0x60, 0xff, 0x4a,
38*4882a593Smuzhiyun 	0x50, 0x3f, 0x10, 0xd2, 0xe3, 0xb3, 0xc9, 0x74,
39*4882a593Smuzhiyun 	0x38, 0x5f, 0xc5, 0xa3, 0xd4, 0xf6, 0x49, 0x3f,
40*4882a593Smuzhiyun };
41*4882a593Smuzhiyun static const u8 priv_b_1[32] __initconst = {
42*4882a593Smuzhiyun 	0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b,
43*4882a593Smuzhiyun 	0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59,
44*4882a593Smuzhiyun 	0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90,
45*4882a593Smuzhiyun 	0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55,
46*4882a593Smuzhiyun };
47*4882a593Smuzhiyun static const u8 pub_a_1[64] __initconst = {
48*4882a593Smuzhiyun 	0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
49*4882a593Smuzhiyun 	0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
50*4882a593Smuzhiyun 	0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
51*4882a593Smuzhiyun 	0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20,
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 	0x8b, 0xd2, 0x89, 0x15, 0xd0, 0x8e, 0x1c, 0x74,
54*4882a593Smuzhiyun 	0x24, 0x30, 0xed, 0x8f, 0xc2, 0x45, 0x63, 0x76,
55*4882a593Smuzhiyun 	0x5c, 0x15, 0x52, 0x5a, 0xbf, 0x9a, 0x32, 0x63,
56*4882a593Smuzhiyun 	0x6d, 0xeb, 0x2a, 0x65, 0x49, 0x9c, 0x80, 0xdc,
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun static const u8 pub_b_1[64] __initconst = {
59*4882a593Smuzhiyun 	0x90, 0xa1, 0xaa, 0x2f, 0xb2, 0x77, 0x90, 0x55,
60*4882a593Smuzhiyun 	0x9f, 0xa6, 0x15, 0x86, 0xfd, 0x8a, 0xb5, 0x47,
61*4882a593Smuzhiyun 	0x00, 0x4c, 0x9e, 0xf1, 0x84, 0x22, 0x59, 0x09,
62*4882a593Smuzhiyun 	0x96, 0x1d, 0xaf, 0x1f, 0xf0, 0xf0, 0xa1, 0x1e,
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	0x4a, 0x21, 0xb1, 0x15, 0xf9, 0xaf, 0x89, 0x5f,
65*4882a593Smuzhiyun 	0x76, 0x36, 0x8e, 0xe2, 0x30, 0x11, 0x2d, 0x47,
66*4882a593Smuzhiyun 	0x60, 0x51, 0xb8, 0x9a, 0x3a, 0x70, 0x56, 0x73,
67*4882a593Smuzhiyun 	0x37, 0xad, 0x9d, 0x42, 0x3e, 0xf3, 0x55, 0x4c,
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun static const u8 dhkey_1[32] __initconst = {
70*4882a593Smuzhiyun 	0x98, 0xa6, 0xbf, 0x73, 0xf3, 0x34, 0x8d, 0x86,
71*4882a593Smuzhiyun 	0xf1, 0x66, 0xf8, 0xb4, 0x13, 0x6b, 0x79, 0x99,
72*4882a593Smuzhiyun 	0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34,
73*4882a593Smuzhiyun 	0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec,
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun static const u8 priv_a_2[32] __initconst = {
77*4882a593Smuzhiyun 	0x63, 0x76, 0x45, 0xd0, 0xf7, 0x73, 0xac, 0xb7,
78*4882a593Smuzhiyun 	0xff, 0xdd, 0x03, 0x72, 0xb9, 0x72, 0x85, 0xb4,
79*4882a593Smuzhiyun 	0x41, 0xb6, 0x5d, 0x0c, 0x5d, 0x54, 0x84, 0x60,
80*4882a593Smuzhiyun 	0x1a, 0xa3, 0x9a, 0x3c, 0x69, 0x16, 0xa5, 0x06,
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun static const u8 priv_b_2[32] __initconst = {
83*4882a593Smuzhiyun 	0xba, 0x30, 0x55, 0x50, 0x19, 0xa2, 0xca, 0xa3,
84*4882a593Smuzhiyun 	0xa5, 0x29, 0x08, 0xc6, 0xb5, 0x03, 0x88, 0x7e,
85*4882a593Smuzhiyun 	0x03, 0x2b, 0x50, 0x73, 0xd4, 0x2e, 0x50, 0x97,
86*4882a593Smuzhiyun 	0x64, 0xcd, 0x72, 0x0d, 0x67, 0xa0, 0x9a, 0x52,
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun static const u8 pub_a_2[64] __initconst = {
89*4882a593Smuzhiyun 	0xdd, 0x78, 0x5c, 0x74, 0x03, 0x9b, 0x7e, 0x98,
90*4882a593Smuzhiyun 	0xcb, 0x94, 0x87, 0x4a, 0xad, 0xfa, 0xf8, 0xd5,
91*4882a593Smuzhiyun 	0x43, 0x3e, 0x5c, 0xaf, 0xea, 0xb5, 0x4c, 0xf4,
92*4882a593Smuzhiyun 	0x9e, 0x80, 0x79, 0x57, 0x7b, 0xa4, 0x31, 0x2c,
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	0x4f, 0x5d, 0x71, 0x43, 0x77, 0x43, 0xf8, 0xea,
95*4882a593Smuzhiyun 	0xd4, 0x3e, 0xbd, 0x17, 0x91, 0x10, 0x21, 0xd0,
96*4882a593Smuzhiyun 	0x1f, 0x87, 0x43, 0x8e, 0x40, 0xe2, 0x52, 0xcd,
97*4882a593Smuzhiyun 	0xbe, 0xdf, 0x98, 0x38, 0x18, 0x12, 0x95, 0x91,
98*4882a593Smuzhiyun };
99*4882a593Smuzhiyun static const u8 pub_b_2[64] __initconst = {
100*4882a593Smuzhiyun 	0xcc, 0x00, 0x65, 0xe1, 0xf5, 0x6c, 0x0d, 0xcf,
101*4882a593Smuzhiyun 	0xec, 0x96, 0x47, 0x20, 0x66, 0xc9, 0xdb, 0x84,
102*4882a593Smuzhiyun 	0x81, 0x75, 0xa8, 0x4d, 0xc0, 0xdf, 0xc7, 0x9d,
103*4882a593Smuzhiyun 	0x1b, 0x3f, 0x3d, 0xf2, 0x3f, 0xe4, 0x65, 0xf4,
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 	0x79, 0xb2, 0xec, 0xd8, 0xca, 0x55, 0xa1, 0xa8,
106*4882a593Smuzhiyun 	0x43, 0x4d, 0x6b, 0xca, 0x10, 0xb0, 0xc2, 0x01,
107*4882a593Smuzhiyun 	0xc2, 0x33, 0x4e, 0x16, 0x24, 0xc4, 0xef, 0xee,
108*4882a593Smuzhiyun 	0x99, 0xd8, 0xbb, 0xbc, 0x48, 0xd0, 0x01, 0x02,
109*4882a593Smuzhiyun };
110*4882a593Smuzhiyun static const u8 dhkey_2[32] __initconst = {
111*4882a593Smuzhiyun 	0x69, 0xeb, 0x21, 0x32, 0xf2, 0xc6, 0x05, 0x41,
112*4882a593Smuzhiyun 	0x60, 0x19, 0xcd, 0x5e, 0x94, 0xe1, 0xe6, 0x5f,
113*4882a593Smuzhiyun 	0x33, 0x07, 0xe3, 0x38, 0x4b, 0x68, 0xe5, 0x62,
114*4882a593Smuzhiyun 	0x3f, 0x88, 0x6d, 0x2f, 0x3a, 0x84, 0x85, 0xab,
115*4882a593Smuzhiyun };
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun static const u8 priv_a_3[32] __initconst = {
118*4882a593Smuzhiyun 	0xbd, 0x1a, 0x3c, 0xcd, 0xa6, 0xb8, 0x99, 0x58,
119*4882a593Smuzhiyun 	0x99, 0xb7, 0x40, 0xeb, 0x7b, 0x60, 0xff, 0x4a,
120*4882a593Smuzhiyun 	0x50, 0x3f, 0x10, 0xd2, 0xe3, 0xb3, 0xc9, 0x74,
121*4882a593Smuzhiyun 	0x38, 0x5f, 0xc5, 0xa3, 0xd4, 0xf6, 0x49, 0x3f,
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun static const u8 pub_a_3[64] __initconst = {
124*4882a593Smuzhiyun 	0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
125*4882a593Smuzhiyun 	0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
126*4882a593Smuzhiyun 	0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
127*4882a593Smuzhiyun 	0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20,
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	0x8b, 0xd2, 0x89, 0x15, 0xd0, 0x8e, 0x1c, 0x74,
130*4882a593Smuzhiyun 	0x24, 0x30, 0xed, 0x8f, 0xc2, 0x45, 0x63, 0x76,
131*4882a593Smuzhiyun 	0x5c, 0x15, 0x52, 0x5a, 0xbf, 0x9a, 0x32, 0x63,
132*4882a593Smuzhiyun 	0x6d, 0xeb, 0x2a, 0x65, 0x49, 0x9c, 0x80, 0xdc,
133*4882a593Smuzhiyun };
134*4882a593Smuzhiyun static const u8 dhkey_3[32] __initconst = {
135*4882a593Smuzhiyun 	0x2d, 0xab, 0x00, 0x48, 0xcb, 0xb3, 0x7b, 0xda,
136*4882a593Smuzhiyun 	0x55, 0x7b, 0x8b, 0x72, 0xa8, 0x57, 0x87, 0xc3,
137*4882a593Smuzhiyun 	0x87, 0x27, 0x99, 0x32, 0xfc, 0x79, 0x5f, 0xae,
138*4882a593Smuzhiyun 	0x7c, 0x1c, 0xf9, 0x49, 0xe6, 0xd7, 0xaa, 0x70,
139*4882a593Smuzhiyun };
140*4882a593Smuzhiyun 
test_ecdh_sample(struct crypto_kpp * tfm,const u8 priv_a[32],const u8 priv_b[32],const u8 pub_a[64],const u8 pub_b[64],const u8 dhkey[32])141*4882a593Smuzhiyun static int __init test_ecdh_sample(struct crypto_kpp *tfm, const u8 priv_a[32],
142*4882a593Smuzhiyun 				   const u8 priv_b[32], const u8 pub_a[64],
143*4882a593Smuzhiyun 				   const u8 pub_b[64], const u8 dhkey[32])
144*4882a593Smuzhiyun {
145*4882a593Smuzhiyun 	u8 *tmp, *dhkey_a, *dhkey_b;
146*4882a593Smuzhiyun 	int ret;
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	tmp = kmalloc(64, GFP_KERNEL);
149*4882a593Smuzhiyun 	if (!tmp)
150*4882a593Smuzhiyun 		return -EINVAL;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	dhkey_a = &tmp[0];
153*4882a593Smuzhiyun 	dhkey_b = &tmp[32];
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	ret = set_ecdh_privkey(tfm, priv_a);
156*4882a593Smuzhiyun 	if (ret)
157*4882a593Smuzhiyun 		goto out;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	ret = compute_ecdh_secret(tfm, pub_b, dhkey_a);
160*4882a593Smuzhiyun 	if (ret)
161*4882a593Smuzhiyun 		goto out;
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 	if (memcmp(dhkey_a, dhkey, 32)) {
164*4882a593Smuzhiyun 		ret = -EINVAL;
165*4882a593Smuzhiyun 		goto out;
166*4882a593Smuzhiyun 	}
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	ret = set_ecdh_privkey(tfm, priv_b);
169*4882a593Smuzhiyun 	if (ret)
170*4882a593Smuzhiyun 		goto out;
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun 	ret = compute_ecdh_secret(tfm, pub_a, dhkey_b);
173*4882a593Smuzhiyun 	if (ret)
174*4882a593Smuzhiyun 		goto out;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	if (memcmp(dhkey_b, dhkey, 32))
177*4882a593Smuzhiyun 		ret = -EINVAL;
178*4882a593Smuzhiyun 	/* fall through*/
179*4882a593Smuzhiyun out:
180*4882a593Smuzhiyun 	kfree(tmp);
181*4882a593Smuzhiyun 	return ret;
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun static char test_ecdh_buffer[32];
185*4882a593Smuzhiyun 
test_ecdh_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)186*4882a593Smuzhiyun static ssize_t test_ecdh_read(struct file *file, char __user *user_buf,
187*4882a593Smuzhiyun 			      size_t count, loff_t *ppos)
188*4882a593Smuzhiyun {
189*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, test_ecdh_buffer,
190*4882a593Smuzhiyun 				       strlen(test_ecdh_buffer));
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun static const struct file_operations test_ecdh_fops = {
194*4882a593Smuzhiyun 	.open		= simple_open,
195*4882a593Smuzhiyun 	.read		= test_ecdh_read,
196*4882a593Smuzhiyun 	.llseek		= default_llseek,
197*4882a593Smuzhiyun };
198*4882a593Smuzhiyun 
test_ecdh(void)199*4882a593Smuzhiyun static int __init test_ecdh(void)
200*4882a593Smuzhiyun {
201*4882a593Smuzhiyun 	struct crypto_kpp *tfm;
202*4882a593Smuzhiyun 	ktime_t calltime, delta, rettime;
203*4882a593Smuzhiyun 	unsigned long long duration = 0;
204*4882a593Smuzhiyun 	int err;
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 	calltime = ktime_get();
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	tfm = crypto_alloc_kpp("ecdh", 0, 0);
209*4882a593Smuzhiyun 	if (IS_ERR(tfm)) {
210*4882a593Smuzhiyun 		BT_ERR("Unable to create ECDH crypto context");
211*4882a593Smuzhiyun 		err = PTR_ERR(tfm);
212*4882a593Smuzhiyun 		goto done;
213*4882a593Smuzhiyun 	}
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun 	err = test_ecdh_sample(tfm, priv_a_1, priv_b_1, pub_a_1, pub_b_1,
216*4882a593Smuzhiyun 			       dhkey_1);
217*4882a593Smuzhiyun 	if (err) {
218*4882a593Smuzhiyun 		BT_ERR("ECDH sample 1 failed");
219*4882a593Smuzhiyun 		goto done;
220*4882a593Smuzhiyun 	}
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	err = test_ecdh_sample(tfm, priv_a_2, priv_b_2, pub_a_2, pub_b_2,
223*4882a593Smuzhiyun 			       dhkey_2);
224*4882a593Smuzhiyun 	if (err) {
225*4882a593Smuzhiyun 		BT_ERR("ECDH sample 2 failed");
226*4882a593Smuzhiyun 		goto done;
227*4882a593Smuzhiyun 	}
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun 	err = test_ecdh_sample(tfm, priv_a_3, priv_a_3, pub_a_3, pub_a_3,
230*4882a593Smuzhiyun 			       dhkey_3);
231*4882a593Smuzhiyun 	if (err) {
232*4882a593Smuzhiyun 		BT_ERR("ECDH sample 3 failed");
233*4882a593Smuzhiyun 		goto done;
234*4882a593Smuzhiyun 	}
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun 	crypto_free_kpp(tfm);
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun 	rettime = ktime_get();
239*4882a593Smuzhiyun 	delta = ktime_sub(rettime, calltime);
240*4882a593Smuzhiyun 	duration = (unsigned long long) ktime_to_ns(delta) >> 10;
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun 	BT_INFO("ECDH test passed in %llu usecs", duration);
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun done:
245*4882a593Smuzhiyun 	if (!err)
246*4882a593Smuzhiyun 		snprintf(test_ecdh_buffer, sizeof(test_ecdh_buffer),
247*4882a593Smuzhiyun 			 "PASS (%llu usecs)\n", duration);
248*4882a593Smuzhiyun 	else
249*4882a593Smuzhiyun 		snprintf(test_ecdh_buffer, sizeof(test_ecdh_buffer), "FAIL\n");
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun 	debugfs_create_file("selftest_ecdh", 0444, bt_debugfs, NULL,
252*4882a593Smuzhiyun 			    &test_ecdh_fops);
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 	return err;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun #else
258*4882a593Smuzhiyun 
test_ecdh(void)259*4882a593Smuzhiyun static inline int test_ecdh(void)
260*4882a593Smuzhiyun {
261*4882a593Smuzhiyun 	return 0;
262*4882a593Smuzhiyun }
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun #endif
265*4882a593Smuzhiyun 
run_selftest(void)266*4882a593Smuzhiyun static int __init run_selftest(void)
267*4882a593Smuzhiyun {
268*4882a593Smuzhiyun 	int err;
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun 	BT_INFO("Starting self testing");
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun 	err = test_ecdh();
273*4882a593Smuzhiyun 	if (err)
274*4882a593Smuzhiyun 		goto done;
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun 	err = bt_selftest_smp();
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun done:
279*4882a593Smuzhiyun 	BT_INFO("Finished self testing");
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun 	return err;
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun #if IS_MODULE(CONFIG_BT)
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun /* This is run when CONFIG_BT_SELFTEST=y and CONFIG_BT=m and is just a
287*4882a593Smuzhiyun  * wrapper to allow running this at module init.
288*4882a593Smuzhiyun  *
289*4882a593Smuzhiyun  * If CONFIG_BT_SELFTEST=n, then this code is not compiled at all.
290*4882a593Smuzhiyun  */
bt_selftest(void)291*4882a593Smuzhiyun int __init bt_selftest(void)
292*4882a593Smuzhiyun {
293*4882a593Smuzhiyun 	return run_selftest();
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun #else
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun /* This is run when CONFIG_BT_SELFTEST=y and CONFIG_BT=y and is run
299*4882a593Smuzhiyun  * via late_initcall() as last item in the initialization sequence.
300*4882a593Smuzhiyun  *
301*4882a593Smuzhiyun  * If CONFIG_BT_SELFTEST=n, then this code is not compiled at all.
302*4882a593Smuzhiyun  */
bt_selftest_init(void)303*4882a593Smuzhiyun static int __init bt_selftest_init(void)
304*4882a593Smuzhiyun {
305*4882a593Smuzhiyun 	return run_selftest();
306*4882a593Smuzhiyun }
307*4882a593Smuzhiyun late_initcall(bt_selftest_init);
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun #endif
310