Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /** * @file smp_null.c * Security Manager Protocol stub */ /* * Copyright (c) 2015-2016 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <nanokernel.h> #include <errno.h> #include <atomic.h> #include <misc/util.h> #include <misc/nano_work.h> #include <bluetooth/log.h> #include <bluetooth/bluetooth.h> #include <bluetooth/conn.h> #include <bluetooth/buf.h> #include "hci_core.h" #include "conn_internal.h" #include "l2cap_internal.h" #include "smp.h" static struct bt_l2cap_le_chan bt_smp_pool[CONFIG_BLUETOOTH_MAX_CONN]; /* Pool for outgoing SMP signaling packets, MTU is 23 */ static struct nano_fifo smp_buf; static NET_BUF_POOL(smp_pool, CONFIG_BLUETOOTH_MAX_CONN, BT_L2CAP_BUF_SIZE(23), &smp_buf, NULL, BT_BUF_USER_DATA_MIN); int bt_smp_sign_verify(struct bt_conn *conn, struct net_buf *buf) { return -ENOTSUP; } int bt_smp_sign(struct bt_conn *conn, struct net_buf *buf) { return -ENOTSUP; } static void bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf) { struct bt_conn *conn = chan->conn; struct bt_smp_pairing_fail *rsp; struct bt_smp_hdr *hdr; /* If a device does not support pairing then it shall respond with * a Pairing Failed command with the reason set to “Pairing Not * Supported” when any command is received. * Core Specification Vol. 3, Part H, 3.3 */ buf = bt_l2cap_create_pdu(&smp_buf); if (!buf) { return; } hdr = net_buf_add(buf, sizeof(*hdr)); hdr->code = BT_SMP_CMD_PAIRING_FAIL; rsp = net_buf_add(buf, sizeof(*rsp)); rsp->reason = BT_SMP_ERR_PAIRING_NOTSUPP; bt_l2cap_send(conn, BT_L2CAP_CID_SMP, buf); } static int bt_smp_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan) { int i; static struct bt_l2cap_chan_ops ops = { .recv = bt_smp_recv, }; BT_DBG("conn %p handle %u", conn, conn->handle); for (i = 0; i < ARRAY_SIZE(bt_smp_pool); i++) { struct bt_l2cap_le_chan *smp = &bt_smp_pool[i]; if (smp->chan.conn) { continue; } smp->chan.ops = &ops; *chan = &smp->chan; return 0; } BT_ERR("No available SMP context for conn %p", conn); return -ENOMEM; } void bt_smp_update_keys(struct bt_conn *conn) { } int bt_smp_create_rpa(const uint8_t irk[16], bt_addr_t *rpa) { return -ENOTSUP; } int bt_smp_init(void) { static struct bt_l2cap_fixed_chan chan = { .cid = BT_L2CAP_CID_SMP, .accept = bt_smp_accept, }; net_buf_pool_init(smp_pool); bt_l2cap_le_fixed_chan_register(&chan); return 0; } |