mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
new: parsing BLE peripheral preferred connection parameters field
This commit is contained in:
parent
cff4b4c11b
commit
5da615f968
1 changed files with 48 additions and 23 deletions
|
@ -220,6 +220,50 @@ func parseRawData(raw []byte) string {
|
||||||
return tui.Yellow(s)
|
return tui.Yellow(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// org.bluetooth.characteristic.gap.appearance
|
||||||
|
func parseAppearance(raw []byte) string {
|
||||||
|
app := binary.LittleEndian.Uint16(raw[0:2])
|
||||||
|
if appName, found := appearances[app]; found {
|
||||||
|
return tui.Green(appName)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("0x%x", app)
|
||||||
|
}
|
||||||
|
|
||||||
|
// org.bluetooth.characteristic.pnp_id
|
||||||
|
func parsePNPID(raw []byte) []string {
|
||||||
|
vendorIdSrc := byte(raw[0])
|
||||||
|
vendorId := binary.LittleEndian.Uint16(raw[1:3])
|
||||||
|
prodId := binary.LittleEndian.Uint16(raw[3:5])
|
||||||
|
prodVer := binary.LittleEndian.Uint16(raw[5:7])
|
||||||
|
|
||||||
|
src := ""
|
||||||
|
if vendorIdSrc == 1 {
|
||||||
|
src = " (Bluetooth SIG assigned Company Identifier)"
|
||||||
|
} else if vendorIdSrc == 2 {
|
||||||
|
src = " (USB Implementer’s Forum assigned Vendor ID value)"
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{
|
||||||
|
tui.Green("Vendor ID") + fmt.Sprintf(": 0x%04x%s", vendorId, tui.Dim(src)),
|
||||||
|
tui.Green("Product ID") + fmt.Sprintf(": 0x%04x", prodId),
|
||||||
|
tui.Green("Product Version") + fmt.Sprintf(": 0x%04x", prodVer),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters
|
||||||
|
func parseConnectionParams(raw []byte) []string {
|
||||||
|
minConInt := binary.LittleEndian.Uint16(raw[0:2])
|
||||||
|
maxConInt := binary.LittleEndian.Uint16(raw[2:4])
|
||||||
|
slaveLat := binary.LittleEndian.Uint16(raw[4:6])
|
||||||
|
conTimeMul := binary.LittleEndian.Uint16(raw[6:8])
|
||||||
|
|
||||||
|
return []string{
|
||||||
|
tui.Green("Connection Interval") + fmt.Sprintf(": %d -> %d", minConInt, maxConInt),
|
||||||
|
tui.Green("Slave Latency") + fmt.Sprintf(": %d", slaveLat),
|
||||||
|
tui.Green("Connection Supervision Timeout Multiplier") + fmt.Sprintf(": %d", conTimeMul),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (mod *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
|
func (mod *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
|
||||||
columns := []string{"Handles", "Service > Characteristics", "Properties", "Data"}
|
columns := []string{"Handles", "Service > Characteristics", "Properties", "Data"}
|
||||||
rows := make([][]string, 0)
|
rows := make([][]string, 0)
|
||||||
|
@ -296,30 +340,11 @@ func (mod *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
|
||||||
multi := ([]string)(nil)
|
multi := ([]string)(nil)
|
||||||
|
|
||||||
if ch.Name() == "Appearance" && sz >= 2 {
|
if ch.Name() == "Appearance" && sz >= 2 {
|
||||||
// org.bluetooth.characteristic.gap.appearance
|
data = parseAppearance(raw)
|
||||||
app := binary.LittleEndian.Uint16(raw[0:2])
|
|
||||||
if appName, found := appearances[app]; found {
|
|
||||||
data = tui.Green(appName)
|
|
||||||
}
|
|
||||||
} else if ch.Name() == "PnP ID" && sz >= 7 {
|
} else if ch.Name() == "PnP ID" && sz >= 7 {
|
||||||
// org.bluetooth.characteristic.pnp_id
|
multi = parsePNPID(raw)
|
||||||
src := ""
|
} else if ch.Name() == "Peripheral Preferred Connection Parameters" && sz >= 8 {
|
||||||
vendorIdSrc := byte(raw[0])
|
multi = parseConnectionParams(raw)
|
||||||
vendorId := binary.LittleEndian.Uint16(raw[1:3])
|
|
||||||
prodId := binary.LittleEndian.Uint16(raw[3:5])
|
|
||||||
prodVer := binary.LittleEndian.Uint16(raw[5:7])
|
|
||||||
|
|
||||||
if vendorIdSrc == 1 {
|
|
||||||
src = " (Bluetooth SIG assigned Company Identifier)"
|
|
||||||
} else if vendorIdSrc == 2 {
|
|
||||||
src = " (USB Implementer’s Forum assigned Vendor ID value)"
|
|
||||||
}
|
|
||||||
|
|
||||||
multi = []string{
|
|
||||||
tui.Green("Vendor ID") + fmt.Sprintf(": 0x%04x%s", vendorId, tui.Dim(src)),
|
|
||||||
tui.Green("Product ID") + fmt.Sprintf(": 0x%04x", prodId),
|
|
||||||
tui.Green("Product Version") + fmt.Sprintf(": 0x%04x", prodVer),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if multi == nil {
|
if multi == nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue