1 /**
2 * @file smp_null.c
3 * Security Manager Protocol stub
4 */
5
6 /*
7 * Copyright (c) 2015-2016 Intel Corporation
8 *
9 * SPDX-License-Identifier: Apache-2.0
10 */
11
12 #include <zephyr/kernel.h>
13 #include <errno.h>
14 #include <zephyr/sys/atomic.h>
15 #include <zephyr/sys/util.h>
16
17 #include <zephyr/bluetooth/bluetooth.h>
18 #include <zephyr/bluetooth/conn.h>
19 #include <zephyr/bluetooth/buf.h>
20
21 #include "hci_core.h"
22 #include "conn_internal.h"
23 #include "l2cap_internal.h"
24 #include "smp.h"
25
26 #define LOG_LEVEL CONFIG_BT_HCI_CORE_LOG_LEVEL
27 #include <zephyr/logging/log.h>
28 LOG_MODULE_REGISTER(bt_smp);
29
30 static struct bt_l2cap_le_chan bt_smp_pool[CONFIG_BT_MAX_CONN];
31
bt_smp_sign_verify(struct bt_conn * conn,struct net_buf * buf)32 int bt_smp_sign_verify(struct bt_conn *conn, struct net_buf *buf)
33 {
34 return -ENOTSUP;
35 }
36
bt_smp_sign(struct bt_conn * conn,struct net_buf * buf)37 int bt_smp_sign(struct bt_conn *conn, struct net_buf *buf)
38 {
39 return -ENOTSUP;
40 }
41
bt_smp_recv(struct bt_l2cap_chan * chan,struct net_buf * req_buf)42 static int bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *req_buf)
43 {
44 struct bt_l2cap_le_chan *le_chan = BT_L2CAP_LE_CHAN(chan);
45 struct bt_smp_pairing_fail *rsp;
46 struct bt_smp_hdr *hdr;
47 struct net_buf *buf;
48
49 ARG_UNUSED(req_buf);
50
51 /* If a device does not support pairing then it shall respond with
52 * a Pairing Failed command with the reason set to "Pairing Not
53 * Supported" when any command is received.
54 * Core Specification Vol. 3, Part H, 3.3
55 */
56
57 buf = bt_l2cap_create_pdu(NULL, 0);
58 /* NULL is not a possible return due to K_FOREVER */
59
60 hdr = net_buf_add(buf, sizeof(*hdr));
61 hdr->code = BT_SMP_CMD_PAIRING_FAIL;
62
63 rsp = net_buf_add(buf, sizeof(*rsp));
64 rsp->reason = BT_SMP_ERR_PAIRING_NOTSUPP;
65
66 if (bt_l2cap_send_pdu(le_chan, buf, NULL, NULL)) {
67 net_buf_unref(buf);
68 }
69
70 return 0;
71 }
72
bt_smp_accept(struct bt_conn * conn,struct bt_l2cap_chan ** chan)73 static int bt_smp_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
74 {
75 int i;
76 static const struct bt_l2cap_chan_ops ops = {
77 .recv = bt_smp_recv,
78 };
79
80 LOG_DBG("conn %p handle %u", conn, conn->handle);
81
82 for (i = 0; i < ARRAY_SIZE(bt_smp_pool); i++) {
83 struct bt_l2cap_le_chan *smp = &bt_smp_pool[i];
84
85 if (smp->chan.conn) {
86 continue;
87 }
88
89 smp->chan.ops = &ops;
90
91 *chan = &smp->chan;
92
93 return 0;
94 }
95
96 LOG_ERR("No available SMP context for conn %p", conn);
97
98 return -ENOMEM;
99 }
100
101 BT_L2CAP_CHANNEL_DEFINE(smp_fixed_chan, BT_L2CAP_CID_SMP, bt_smp_accept, NULL);
102
bt_smp_init(void)103 int bt_smp_init(void)
104 {
105 return 0;
106 }
107