1 // Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // #include <bt_errno.h>
16 // #include <string.h>
17 #include <ble_os.h>
18 #include <api/mesh.h>
19 
20 #ifdef CONFIG_BT_MESH_PROVISIONER
21 
22 #include <bt_errno.h>
23 #include <atomic.h>
24 #include <misc/util.h>
25 #include <misc/byteorder.h>
26 
27 #include <net/buf.h>
28 #include <bluetooth/conn.h>
29 
30 
31 #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_BEACON)
32 #include "common/log.h"
33 
34 #include "adv.h"
35 #include "mesh.h"
36 #include "net.h"
37 #include "prov.h"
38 //#include "crypto.h"
39 #include "beacon.h"
40 #include "foundation.h"
41 
42 #include "provisioner_prov.h"
43 
44 //#include "bt_mesh_custom_log.h"
45 
provisioner_secure_beacon_recv(struct net_buf_simple * buf)46 static void provisioner_secure_beacon_recv(struct net_buf_simple *buf)
47 {
48     // TODO: Provisioner receive and handle Secure Beacon
49 }
50 
provisioner_beacon_recv(struct net_buf_simple * buf)51 void provisioner_beacon_recv(struct net_buf_simple *buf)
52 {
53     u8_t type;
54 
55     BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len));
56 
57     if (buf->len < 1) {
58         BT_ERR("Too short beacon");
59         return;
60     }
61 
62     type = net_buf_simple_pull_u8(buf);
63     switch (type) {
64     case BEACON_TYPE_UNPROVISIONED:
65         BT_DBG("Unprovisioned device beacon received");
66         provisioner_unprov_beacon_recv(buf);
67         break;
68     case BEACON_TYPE_SECURE:
69         provisioner_secure_beacon_recv(buf);
70         break;
71     default:
72         BT_WARN("Unknown beacon type 0x%02x", type);
73         break;
74     }
75 }
76 
77 #endif /* CONFIG_BT_MESH_PROVISIONER */
78