hci-decoder  1.0
Lightweight Bluetooth HCI decoder library parsing individually HCI frames into JSON format
hci_global.h
Go to the documentation of this file.
1 /************************************************************************************
2  * The MIT License (MIT) *
3  * *
4  * Copyright (c) 2015 Bertrand Martel *
5  * *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy *
7  * of this software and associated documentation files (the "Software"), to deal *
8  * in the Software without restriction, including without limitation the rights *
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
10  * copies of the Software, and to permit persons to whom the Software is *
11  * furnished to do so, subject to the following conditions: *
12  * *
13  * The above copyright notice and this permission notice shall be included in *
14  * all copies or substantial portions of the Software. *
15  * *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
22  * THE SOFTWARE. *
23  ************************************************************************************/
31 #ifndef HCIGLOBAL_H
32 #define HCIGLOBAL_H
33 
34 #include <iostream>
35 #include <json/json.h>
36 
37 //excluding command code decode from parameter length field
38 #define COMMAND_FRAME_OFFSET 3
39 
40 //excluding event code decode from parameter length field
41 #define EVENT_FRAME_OFFSET 2
42 
43 #define ACL_FRAME_OFFSET 1
44 
45 #define E(x,y) x = y,
48 };
49 
50 #define E(x,y) { x,#x },
51 const std::map< int, std::string> COMMAND_OCF_LE_STRING_ENUM = {
53 };
54 
55 #define E(x,y) x = y,
58 };
59 
60 #define E(x,y) { x,#x },
61 const std::map< int, std::string> COMMAND_OCF_CTRL_BSB_STRING_ENUM = {
63 };
64 
65 #define E(x,y) x = y,
68 };
69 
70 #define E(x,y) { x,#x },
71 const std::map< int, std::string> COMMAND_OCF_INFORMATIONAL_STRING_ENUM = {
73 };
74 
75 #define E(x,y) x = y,
78 };
79 
80 #define E(x,y) { x,#x },
81 const std::map< int, std::string> COMMAND_OCF_LINK_POLICY_STRING_ENUM = {
83 };
84 
85 #define E(x,y) x = y,
88 };
89 
90 #define E(x,y) { x,#x },
91 const std::map< int, std::string> COMMAND_OCF_LINK_CONTROL_STRING_ENUM = {
93 };
94 
95 #define E(x,y) x = y,
96 enum EVENT_ENUM {
97 #include "hci_decoder/hci_event.h"
98 };
99 
100 #define E(x,y) { x,#x },
101 const std::map< int, std::string> EVENT_STRING_ENUM = {
102 #include "hci_decoder/hci_event.h"
103 };
104 
105 #define E(x,y) x = y,
108 };
109 
110 #define E(x,y) { x,#x },
111 const std::map< int, std::string> LE_SUBEVENT_STRING_ENUM = {
113 };
114 
115 #define E(x,y) x = y,
117 #include "hci_decoder/hci_ogf.h"
118 };
119 
120 #define E(x,y) { x,#x },
121 const std::map< int, std::string> COMMAND_OGF_STRING_ENUM = {
122 #include "hci_decoder/hci_ogf.h"
123 };
124 
125 #define E(x,y) x = y,
128 };
129 
130 #define E(x,y) { x,#x },
131 const std::map< int, std::string> HCI_PACKET_TYPE_STRING_ENUM = {
133 };
134 
135 
136 struct bt_address{
137 
138  uint8_t address[6];
139 
140  void print(){
141  printf("address : %02X:%02X:%02X:%02X:%02X:%02X\n",address[0],address[1],address[2],address[3],address[4],address[5]);
142  }
143 
144  std::string toString(){
145  char output[24];
146  sprintf(output,"%02X:%02X:%02X:%02X:%02X:%02X",address[0],address[1],address[2],address[3],address[4],address[5]);
147  std::string out = output;
148  return out;
149  }
150 
151 };
152 
153 inline uint8_t get_ogf(uint8_t data){
154  return (data>>2);
155 }
156 
157 inline uint8_t get_ocf(uint8_t msb,uint8_t lsb){
158  return ((msb & 0x03) + lsb);
159 }
160 
164 inline std::string convert_json_to_string(bool beautify,Json::Value output){
165 
166  if (!beautify){
167  Json::StreamWriterBuilder builder;
168  builder.settings_["indentation"] = "";
169  return Json::writeString(builder, output);
170  }
171  else{
172  return output.toStyledString();
173  }
174 }
175 
176 #endif // HCIGLOBAL_H
std::string toString()
Definition: hci_global.h:144
const std::map< int, std::string > COMMAND_OCF_LINK_POLICY_STRING_ENUM
Definition: hci_global.h:81
uint8_t address[6]
Definition: hci_global.h:138
COMMAND_OCF_CTRL_BSB_ENUM
Definition: hci_global.h:56
HCI_PACKET_TYPE_ENUM
Definition: hci_global.h:126
const std::map< int, std::string > COMMAND_OCF_LINK_CONTROL_STRING_ENUM
Definition: hci_global.h:91
EVENT_ENUM
Definition: hci_global.h:96
const std::map< int, std::string > COMMAND_OCF_LE_STRING_ENUM
Definition: hci_global.h:51
COMMAND_OCF_LINK_POLICY_ENUM
Definition: hci_global.h:76
uint8_t get_ocf(uint8_t msb, uint8_t lsb)
Definition: hci_global.h:157
COMMAND_OCF_INFORMATIONAL_ENUM
Definition: hci_global.h:66
LE_SUBEVENT_ENUM
Definition: hci_global.h:106
std::string convert_json_to_string(bool beautify, Json::Value output)
Definition: hci_global.h:164
const std::map< int, std::string > LE_SUBEVENT_STRING_ENUM
Definition: hci_global.h:111
const std::map< int, std::string > HCI_PACKET_TYPE_STRING_ENUM
Definition: hci_global.h:131
void print()
Definition: hci_global.h:140
const std::map< int, std::string > COMMAND_OCF_CTRL_BSB_STRING_ENUM
Definition: hci_global.h:61
const std::map< int, std::string > COMMAND_OGF_STRING_ENUM
Definition: hci_global.h:121
uint8_t get_ogf(uint8_t data)
Definition: hci_global.h:153
const std::map< int, std::string > COMMAND_OCF_INFORMATIONAL_STRING_ENUM
Definition: hci_global.h:71
COMMAND_OGF_ENUM
Definition: hci_global.h:116
COMMAND_OCF_LINK_CONTROL_ENUM
Definition: hci_global.h:86
COMMAND_OCF_LE_ENUM
Definition: hci_global.h:46
Definition: hci_global.h:136
const std::map< int, std::string > EVENT_STRING_ENUM
Definition: hci_global.h:101