-
Notifications
You must be signed in to change notification settings - Fork 217
Files
/
Copy pathHCI.cpp
Latest commit
1502 lines (1341 loc) · 46.8 KB
1
/*
2
This file is part of the ArduinoBLE library.
3
Copyright (c) 2018 Arduino SA. All rights reserved.
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
#include "ATT.h"
21
#include "GAP.h"
22
#include "HCITransport.h"
23
#include "L2CAPSignaling.h"
24
#include "btct.h"
25
#include "HCI.h"
26
#include "bitDescriptions.h"
27
// #define _BLE_TRACE_
28
29
30
#define HCI_COMMAND_PKT 0x01
31
#define HCI_ACLDATA_PKT 0x02
32
#define HCI_EVENT_PKT 0x04
33
#define HCI_SECURITY_PKT 0x06
34
35
#define EVT_DISCONN_COMPLETE 0x05
36
#define EVT_ENCRYPTION_CHANGE 0x08
37
#define EVT_CMD_COMPLETE 0x0e
38
#define EVT_CMD_STATUS 0x0f
39
#define EVT_NUM_COMP_PKTS 0x13
40
#define EVT_RETURN_LINK_KEYS 0x15
41
#define EVT_UNKNOWN 0x10
42
#define EVT_LE_META_EVENT 0x3e
43
44
#define EVT_LE_CONN_COMPLETE 0x01
45
#define EVT_LE_ADVERTISING_REPORT 0x02
46
47
48
// OGF_LINK_CTL
49
#define OCF_DISCONNECT 0x0006
50
51
// OGF_HOST_CTL
52
#define OCF_SET_EVENT_MASK 0x0001
53
#define OCF_RESET 0x0003
54
55
// OGF_INFO_PARAM
56
#define OCF_READ_LOCAL_VERSION 0x0001
57
#define OCF_READ_BD_ADDR 0x0009
58
59
// OGF_STATUS_PARAM
60
#define OCF_READ_RSSI 0x0005
61
62
// OGF_LE_CTL
63
#define OCF_LE_READ_BUFFER_SIZE 0x0002
64
#define OCF_LE_SET_RANDOM_ADDRESS 0x0005
65
#define OCF_LE_SET_ADVERTISING_PARAMETERS 0x0006
66
#define OCF_LE_SET_ADVERTISING_DATA 0x0008
67
#define OCF_LE_SET_SCAN_RESPONSE_DATA 0x0009
68
#define OCF_LE_SET_ADVERTISE_ENABLE 0x000a
69
#define OCF_LE_SET_SCAN_PARAMETERS 0x000b
70
#define OCF_LE_SET_SCAN_ENABLE 0x000c
71
#define OCF_LE_CREATE_CONN 0x000d
72
#define OCF_LE_CANCEL_CONN 0x000e
73
#define OCF_LE_CONN_UPDATE 0x0013
74
75
#define HCI_OE_USER_ENDED_CONNECTION 0x13
76
77
String metaEventToString(LE_META_EVENT event)
78
{
79
switch(event){
80
case CONN_COMPLETE: return F("CONN_COMPLETE");
81
case ADVERTISING_REPORT: return F("ADVERTISING_REPORT");
82
case LONG_TERM_KEY_REQUEST: return F("LE_LONG_TERM_KEY_REQUEST");
83
case READ_LOCAL_P256_COMPLETE: return F("READ_LOCAL_P256_COMPLETE");
84
case GENERATE_DH_KEY_COMPLETE: return F("GENERATE_DH_KEY_COMPLETE");
85
case ENHANCED_CONN_COMPLETE: return F("ENHANCED_CONN_COMPLETE");
86
default: return "event unknown";
87
}
88
}
89
String commandToString(LE_COMMAND command){
90
switch (command)
91
{
92
case ENCRYPT: return F("ENCRYPT");
93
case LONG_TERM_KEY_REPLY: return F("LONG_TERM_KEY_REPLY");
94
case READ_LOCAL_P256: return F("READ_LOCAL_P256");
95
case GENERATE_DH_KEY_V1: return F("GENERATE_DH_KEY_V1");
96
case GENERATE_DH_KEY_V2: return F("GENERATE_DH_KEY_V2");
97
default: return "UNKNOWN";
98
}
99
}
100
101
HCIClass::HCIClass() :