Debian Codegraph @

modules/ble/ble_show_services.go

raw symbols SCIP
1 // +build !windows
2
3 package blescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/
4
5 import (
6 "encoding/binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/"
7 "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/"
8 "strconvscip-go gomod github.com/golang/go/src go1.16 strconv/"
9 "stringsscip-go gomod github.com/golang/go/src go1.16 strings/"
10
11 "github.com/bettercap/bettercap/networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/"
12 "github.com/bettercap/gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/"
13
14 "github.com/evilsocket/islazy/tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/"
15 )
16
17 var appearancesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/appearances. = map[uint16]string{
18 0: "Unknown",
19 64: "Generic Phone",
20 128: "Generic Computer",
21 192: "Generic Watch",
22 193: "Watch: Sports Watch",
23 256: "Generic Clock",
24 320: "Generic Display",
25 384: "Generic Remote Control",
26 448: "Generic Eye-glasses",
27 512: "Generic Tag",
28 576: "Generic Keyring",
29 640: "Generic Media Player",
30 704: "Generic Barcode Scanner",
31 768: "Generic Thermometer",
32 769: "Thermometer: Ear",
33 832: "Generic Heart rate Sensor",
34 833: "Heart Rate Sensor: Heart Rate Belt",
35 896: "Generic Blood Pressure",
36 897: "Blood Pressure: Arm",
37 898: "Blood Pressure: Wrist",
38 960: "Human Interface Device (HID)",
39 961: "Keyboard",
40 962: "Mouse",
41 963: "Joystick",
42 964: "Gamepad",
43 965: "Digitizer Tablet",
44 966: "Card Reader",
45 967: "Digital Pen",
46 968: "Barcode Scanner",
47 1024: "Generic Glucose Meter",
48 1088: "Generic: Running Walking Sensor",
49 1089: "Running Walking Sensor: In-Shoe",
50 1090: "Running Walking Sensor: On-Shoe",
51 1091: "Running Walking Sensor: On-Hip",
52 1152: "Generic: Cycling",
53 1153: "Cycling: Cycling Computer",
54 1154: "Cycling: Speed Sensor",
55 1155: "Cycling: Cadence Sensor",
56 1156: "Cycling: Power Sensor",
57 1157: "Cycling: Speed and Cadence Sensor",
58 1216: "Generic Control Device",
59 1217: "Switch",
60 1218: "Multi-switch",
61 1219: "Button",
62 1220: "Slider",
63 1221: "Rotary",
64 1222: "Touch-panel",
65 1280: "Generic Network Device",
66 1281: "Access Point",
67 1344: "Generic Sensor",
68 1345: "Motion Sensor",
69 1346: "Air Quality Sensor",
70 1347: "Temperature Sensor",
71 1348: "Humidity Sensor",
72 1349: "Leak Sensor",
73 1350: "Smoke Sensor",
74 1351: "Occupancy Sensor",
75 1352: "Contact Sensor",
76 1353: "Carbon Monoxide Sensor",
77 1354: "Carbon Dioxide Sensor",
78 1355: "Ambient Light Sensor",
79 1356: "Energy Sensor",
80 1357: "Color Light Sensor",
81 1358: "Rain Sensor",
82 1359: "Fire Sensor",
83 1360: "Wind Sensor",
84 1361: "Proximity Sensor",
85 1362: "Multi-Sensor",
86 1408: "Generic Light Fixtures",
87 1409: "Wall Light",
88 1410: "Ceiling Light",
89 1411: "Floor Light",
90 1412: "Cabinet Light",
91 1413: "Desk Light",
92 1414: "Troffer Light",
93 1415: "Pendant Light",
94 1416: "In-ground Light",
95 1417: "Flood Light",
96 1418: "Underwater Light",
97 1419: "Bollard with Light",
98 1420: "Pathway Light",
99 1421: "Garden Light",
100 1422: "Pole-top Light",
101 1423: "Spotlight",
102 1424: "Linear Light",
103 1425: "Street Light",
104 1426: "Shelves Light",
105 1427: "High-bay / Low-bay Light",
106 1428: "Emergency Exit Light",
107 1472: "Generic Fan",
108 1473: "Ceiling Fan",
109 1474: "Axial Fan",
110 1475: "Exhaust Fan",
111 1476: "Pedestal Fan",
112 1477: "Desk Fan",
113 1478: "Wall Fan",
114 1536: "Generic HVAC",
115 1537: "Thermostat",
116 1600: "Generic Air Conditioning",
117 1664: "Generic Humidifier",
118 1728: "Generic Heating",
119 1729: "Radiator",
120 1730: "Boiler",
121 1731: "Heat Pump",
122 1732: "Infrared Heater",
123 1733: "Radiant Panel Heater",
124 1734: "Fan Heater",
125 1735: "Air Curtain",
126 1792: "Generic Access Control",
127 1793: "Access Door",
128 1794: "Garage Door",
129 1795: "Emergency Exit Door",
130 1796: "Access Lock",
131 1797: "Elevator",
132 1798: "Window",
133 1799: "Entrance Gate",
134 1856: "Generic Motorized Device",
135 1857: "Motorized Gate",
136 1858: "Awning",
137 1859: "Blinds or Shades",
138 1860: "Curtains",
139 1861: "Screen",
140 1920: "Generic Power Device",
141 1921: "Power Outlet",
142 1922: "Power Strip",
143 1923: "Plug",
144 1924: "Power Supply",
145 1925: "LED Driver",
146 1926: "Fluorescent Lamp Gear",
147 1927: "HID Lamp Gear",
148 1984: "Generic Light Source",
149 1985: "Incandescent Light Bulb",
150 1986: "LED Bulb",
151 1987: "HID Lamp",
152 1988: "Fluorescent Lamp",
153 1989: "LED Array",
154 1990: "Multi-Color LED Array",
155 3136: "Generic: Pulse Oximeter",
156 3137: "Fingertip",
157 3138: "Wrist Worn",
158 3200: "Generic: Weight Scale",
159 3264: "Generic",
160 3265: "Powered Wheelchair",
161 3266: "Mobility Scooter",
162 3328: "Generic",
163 5184: "Generic: Outdoor Sports Activity",
164 5185: "Location Display Device",
165 5186: "Location and Navigation Display Device",
166 5187: "Location Pod",
167 5188: "Location and Navigation Pod",
168 }
169
170 func parsePropertiesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parseProperties().(ch *gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.Characteristicscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#) (props []string, isReadable bool, isWritable bool, withResponse bool) {
171 isReadable = false
172 isWritable = false
173 withResponse = false
174 props = make([]string, 0)
175 mask := ch.Propertiesscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#Properties().()
176
177 if (mask & gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharBroadcastscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharBroadcast.) != 0 {
178 props = append(props, "BCAST")
179 }
180 if (mask & gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharReadscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharRead.) != 0 {
181 isReadable = true
182 props = append(props, "READ")
183 }
184 if (mask&gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharWriteNRscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharWriteNR.) != 0 || (mask&gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharWritescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharWrite.) != 0 {
185 props = append(props, tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Boldscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Bold().("WRITE"))
186 isWritable = true
187 withResponse = (mask & gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharWriteNRscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharWriteNR.) == 0
188 }
189 if (mask & gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharNotifyscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharNotify.) != 0 {
190 props = append(props, "NOTIFY")
191 }
192 if (mask & gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharIndicatescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharIndicate.) != 0 {
193 props = append(props, "INDICATE")
194 }
195 if (mask & gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharSignedWritescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharSignedWrite.) != 0 {
196 props = append(props, tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Yellowscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Yellow().("SIGN WRITE"))
197 isWritable = true
198 withResponse = true
199 }
200 if (mask & gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.CharExtendedscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/CharExtended.) != 0 {
201 props = append(props, "X")
202 }
203
204 return
205 }
206
207 func parseRawDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parseRawData().(raw []byte) string {
208 s := ""
209 for _, b := range raw {
210 if strconvscip-go gomod github.com/golang/go/src go1.16 strconv/.IsPrintscip-go gomod github.com/golang/go/src go1.16 strconv/IsPrint().(rune(b)) {
211 s += tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Yellowscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Yellow().(string(b))
212 } else {
213 s += tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Dimscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Dim().(fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%02x", b))
214 }
215 }
216 return s
217 }
218
219 // org.bluetooth.characteristic.gap.appearance
220 func parseAppearancescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parseAppearance().(raw []byte) string {
221 app := binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/LittleEndian..Uint16scip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/littleEndian#Uint16().(raw[0:2])
222 if appName, found := appearancesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/appearances.[app]; found {
223 return tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().(appName)
224 }
225 return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("0x%x", app)
226 }
227
228 // org.bluetooth.characteristic.pnp_id
229 func parsePNPIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parsePNPID().(raw []byte) []string {
230 vendorIdSrc := byte(raw[0])
231 vendorId := binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/LittleEndian..Uint16scip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/littleEndian#Uint16().(raw[1:3])
232 prodId := binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/LittleEndian..Uint16scip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/littleEndian#Uint16().(raw[3:5])
233 prodVer := binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/LittleEndian..Uint16scip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/littleEndian#Uint16().(raw[5:7])
234
235 src := ""
236 if vendorIdSrc == 1 {
237 src = " (Bluetooth SIG assigned Company Identifier)"
238 } else if vendorIdSrc == 2 {
239 src = " (USB Implementer’s Forum assigned Vendor ID value)"
240 }
241
242 return []string{
243 tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().("Vendor ID") + fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(": 0x%04x%s", vendorId, tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Dimscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Dim().(src)),
244 tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().("Product ID") + fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(": 0x%04x", prodId),
245 tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().("Product Version") + fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(": 0x%04x", prodVer),
246 }
247 }
248
249 // org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters
250 func parseConnectionParamsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parseConnectionParams().(raw []byte) []string {
251 minConInt := binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/LittleEndian..Uint16scip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/littleEndian#Uint16().(raw[0:2])
252 maxConInt := binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/LittleEndian..Uint16scip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/littleEndian#Uint16().(raw[2:4])
253 slaveLat := binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/LittleEndian..Uint16scip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/littleEndian#Uint16().(raw[4:6])
254 conTimeMul := binaryscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/LittleEndian..Uint16scip-go gomod github.com/golang/go/src go1.16 `encoding/binary`/littleEndian#Uint16().(raw[6:8])
255
256 return []string{
257 tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().("Connection Interval") + fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(": %d -> %d", minConInt, maxConInt),
258 tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().("Slave Latency") + fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(": %d", slaveLat),
259 tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().("Connection Supervision Timeout Multiplier") + fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(": %d", conTimeMul),
260 }
261 }
262
263 // org.bluetooth.characteristic.gap.peripheral_privacy_flag
264 func parsePrivacyFlagscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parsePrivacyFlag().(raw []byte) string {
265 if raw[0] == 0x0 {
266 return tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().("Privacy Disabled")
267 }
268 return tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Redscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Red().("Privacy Enabled")
269 }
270
271 func (mod *BLEReconscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#) showServicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#showServices().(p gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.Peripheralscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Peripheral#, services []*gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.Servicescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#) {
272 columns := []string{"Handles", "Service > Characteristics", "Properties", "Data"}
273 rows := make([][]string, 0)
274
275 wantsToWrite := mod.writeUUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#writeUUID. != nil
276 foundToWrite := false
277
278 mod.currDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#currDevice..Servicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Services. = make([]networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.BLEServicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#, 0)
279
280 for _, svc := range services {
281 service := networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.BLEServicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#{
282 UUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#UUID.: svc.UUIDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#UUID().().Stringscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/UUID#String().(),
283 Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#Name.: svc.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#Name().(),
284 Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#Handle.: svc.Handlescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#Handle().(),
285 EndHandlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#EndHandle.: svc.EndHandlescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#EndHandle().(),
286 Characteristicsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#Characteristics.: make([]networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.BLECharacteristicscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#, 0),
287 }
288
289 mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Eventsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Events..Addscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/EventPool#Add().("ble.device.service.discovered", svc)
290
291 name := svc.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#Name().()
292 if name == "" {
293 name = svc.UUIDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#UUID().().Stringscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/UUID#String().()
294 } else {
295 name = fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%s (%s)", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().(name), tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Dimscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Dim().(svc.UUIDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#UUID().().Stringscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/UUID#String().()))
296 }
297
298 row := []string{
299 fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%04x -> %04x", svc.Handlescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#Handle().(), svc.EndHandlescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#EndHandle().()),
300 name,
301 "",
302 "",
303 }
304
305 rows = append(rows, row)
306
307 chars, err := p.DiscoverCharacteristicsscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Peripheral#DiscoverCharacteristics().(nil, svc)
308 if err != nil {
309 mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("error while enumerating chars for service %s: %s", svc.UUIDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Service#UUID().(), err)
310 } else {
311 for _, ch := range chars {
312 props, isReadable, isWritable, withResponse := parsePropertiesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parseProperties().(ch)
313
314 char := networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.BLECharacteristicscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#{
315 UUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#UUID.: ch.UUIDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#UUID().().Stringscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/UUID#String().(),
316 Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Name.: ch.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#Name().(),
317 Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Handle.: ch.VHandlescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#VHandle().(),
318 Propertiesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Properties.: props,
319 }
320
321 mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Eventsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Events..Addscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/EventPool#Add().("ble.device.characteristic.discovered", ch)
322
323 name = ch.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#Name().()
324 if name == "" {
325 name = " " + ch.UUIDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#UUID().().Stringscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/UUID#String().()
326 } else {
327 name = fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(" %s (%s)", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().(name), tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Dimscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Dim().(ch.UUIDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#UUID().().Stringscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/UUID#String().()))
328 }
329
330 if wantsToWrite && mod.writeUUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#writeUUID..Equalscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/UUID#Equal().(ch.UUIDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#UUID().()) {
331 foundToWrite = true
332 if isWritable {
333 mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("writing %d bytes to characteristics %s ...", len(mod.writeDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#writeData.), mod.writeUUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#writeUUID.)
334 } else {
335 mod.Warningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Warning().("attempt to write %d bytes to non writable characteristics %s ...", len(mod.writeDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#writeData.), mod.writeUUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#writeUUID.)
336 }
337
338 if err := p.WriteCharacteristicscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Peripheral#WriteCharacteristic().(ch, mod.writeDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#writeData., !withResponse); err != nil {
339 mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("error while writing: %s", err)
340 }
341 }
342
343 sz := 0
344 raw := ([]byte)(nil)
345 err := error(nil)
346 if isReadable {
347 if raw, err = p.ReadCharacteristicscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Peripheral#ReadCharacteristic().(ch); raw != nil {
348 sz = len(raw)
349 }
350 }
351
352 data := ""
353 multi := ([]string)(nil)
354 if err != nil {
355 data = tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Redscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Red().(err.Error())
356 } else if ch.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#Name().() == "Appearance" && sz >= 2 {
357 data = parseAppearancescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parseAppearance().(raw)
358 } else if ch.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#Name().() == "PnP ID" && sz >= 7 {
359 multi = parsePNPIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parsePNPID().(raw)
360 } else if ch.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#Name().() == "Peripheral Preferred Connection Parameters" && sz >= 8 {
361 multi = parseConnectionParamsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parseConnectionParams().(raw)
362 } else if ch.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#Name().() == "Peripheral Privacy Flag" && sz >= 1 {
363 data = parsePrivacyFlagscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parsePrivacyFlag().(raw)
364 } else {
365 data = parseRawDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/parseRawData().(raw)
366 }
367
368 if ch.Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#Name().() == "Device Name" && data != "" && mod.currDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#currDevice..DeviceNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#DeviceName. == "" {
369 mod.currDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#currDevice..DeviceNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#DeviceName. = data
370 }
371
372 if multi == nil {
373 char.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Data. = data
374 rows = append(rows, []string{
375 fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%04x", ch.VHandlescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#VHandle().()),
376 name,
377 stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Joinscip-go gomod github.com/golang/go/src go1.16 strings/Join().(props, ", "),
378 data,
379 })
380 } else {
381 char.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Data. = multi
382 for i, m := range multi {
383 if i == 0 {
384 rows = append(rows, []string{
385 fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%04x", ch.VHandlescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Characteristic#VHandle().()),
386 name,
387 stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Joinscip-go gomod github.com/golang/go/src go1.16 strings/Join().(props, ", "),
388 m,
389 })
390 } else {
391 rows = append(rows, []string{"", "", "", m})
392 }
393 }
394 }
395
396 service.Characteristicsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#Characteristics. = append(service.Characteristicsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#Characteristics., char)
397 }
398 // blank row after every service, bleah style
399 rows = append(rows, []string{"", "", "", ""})
400 }
401
402 mod.currDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#currDevice..Servicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Services. = append(mod.currDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#currDevice..Servicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Services., service)
403 }
404
405 if wantsToWrite && !foundToWrite {
406 mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("writable characteristics %s not found.", mod.writeUUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/ble`/BLERecon#writeUUID.)
407 } else {
408 tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Tablescip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Table().(mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Eventsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Events..Stdoutscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/EventPool#Stdout., columns, rows)
409 mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Refreshscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Refresh().()
410 }
411 }