1 /* main.c - Application main entry point */
2 
3 /*
4  * Copyright (c) 2019 Intel Corporation
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <zephyr/kernel.h>
10 #include <stddef.h>
11 #include <zephyr/ztest.h>
12 
13 #include <zephyr/bluetooth/buf.h>
14 #include <zephyr/bluetooth/bluetooth.h>
15 #include <zephyr/bluetooth/l2cap.h>
16 
l2cap_accept(struct bt_conn * conn,struct bt_l2cap_server * server,struct bt_l2cap_chan ** chan)17 static int l2cap_accept(struct bt_conn *conn, struct bt_l2cap_server *server,
18 			struct bt_l2cap_chan **chan)
19 {
20 	return -ENOSYS;
21 }
22 
23 static struct bt_l2cap_server test_server = {
24 	.accept		= l2cap_accept,
25 };
26 
27 static struct bt_l2cap_server test_fixed_server = {
28 	.accept		= l2cap_accept,
29 	.psm		= 0x007f,
30 };
31 
32 static struct bt_l2cap_server test_dyn_server = {
33 	.accept		= l2cap_accept,
34 	.psm		= 0x00ff,
35 };
36 
37 static struct bt_l2cap_server test_inv_server = {
38 	.accept		= l2cap_accept,
39 	.psm		= 0xffff,
40 };
41 
42 ZTEST_SUITE(test_l2cap, NULL, NULL, NULL, NULL, NULL);
43 
ZTEST(test_l2cap,test_l2cap_register)44 ZTEST(test_l2cap, test_l2cap_register)
45 {
46 	/* Attempt to register server with PSM auto allocation */
47 	zassert_false(bt_l2cap_server_register(&test_server),
48 		     "Test server registration failed");
49 
50 	/* Attempt to register server with fixed PSM */
51 	zassert_false(bt_l2cap_server_register(&test_fixed_server),
52 		     "Test fixed PSM server registration failed");
53 
54 	/* Attempt to register server with dynamic PSM */
55 	zassert_false(bt_l2cap_server_register(&test_dyn_server),
56 		     "Test dynamic PSM server registration failed");
57 
58 	/* Attempt to register server with invalid PSM */
59 	zassert_true(bt_l2cap_server_register(&test_inv_server),
60 		     "Test invalid PSM server registration succeeded");
61 
62 	/* Attempt to re-register server with PSM auto allocation */
63 	zassert_true(bt_l2cap_server_register(&test_server),
64 		     "Test server duplicate succeeded");
65 
66 	/* Attempt to re-register server with fixed PSM */
67 	zassert_true(bt_l2cap_server_register(&test_fixed_server),
68 		     "Test fixed PSM server duplicate succeeded");
69 
70 	/* Attempt to re-register server with dynamic PSM */
71 	zassert_true(bt_l2cap_server_register(&test_dyn_server),
72 		     "Test dynamic PSM server duplicate succeeded");
73 }
74