| 1 | // +build !windows |
| 2 | |
| 3 | package networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/ |
| 4 | |
| 5 | import ( |
| 6 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/" |
| 7 | "timescip-go gomod github.com/golang/go/src go1.16 time/" |
| 8 | |
| 9 | "github.com/bettercap/gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/" |
| 10 | ) |
| 11 | |
| 12 | type BLECharacteristicscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic# struct { |
| 13 | UUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#UUID. string `json:"uuid"` |
| 14 | Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Name. string `json:"name"` |
| 15 | Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Handle. uint16 `json:"handle"` |
| 16 | Propertiesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Properties. []string `json:"properties"` |
| 17 | Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic#Data. interface{} `json:"data"` |
| 18 | } |
| 19 | |
| 20 | type BLEServicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService# struct { |
| 21 | UUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#UUID. string `json:"uuid"` |
| 22 | Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#Name. string `json:"name"` |
| 23 | Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#Handle. uint16 `json:"handle"` |
| 24 | EndHandlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#EndHandle. uint16 `json:"end_handle"` |
| 25 | Characteristicsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#Characteristics. []BLECharacteristicscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLECharacteristic# `json:"characteristics"` |
| 26 | } |
| 27 | |
| 28 | type BLEDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice# struct { |
| 29 | Aliasscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Alias. string |
| 30 | LastSeenscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#LastSeen. timescip-go gomod github.com/golang/go/src go1.16 time/.Timescip-go gomod github.com/golang/go/src go1.16 time/Time# |
| 31 | DeviceNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#DeviceName. string |
| 32 | Vendorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Vendor. string |
| 33 | RSSIscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#RSSI. int |
| 34 | Devicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Device. 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# |
| 35 | Advertisementscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Advertisement. *gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.Advertisementscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Advertisement# |
| 36 | Servicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Services. []BLEServicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService# |
| 37 | } |
| 38 | |
| 39 | type bleDeviceJSONscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON# struct { |
| 40 | LastSeenscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#LastSeen. timescip-go gomod github.com/golang/go/src go1.16 time/.Timescip-go gomod github.com/golang/go/src go1.16 time/Time# `json:"last_seen"` |
| 41 | Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Name. string `json:"name"` |
| 42 | MACscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#MAC. string `json:"mac"` |
| 43 | Aliasscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Alias. string `json:"alias"` |
| 44 | Vendorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Vendor. string `json:"vendor"` |
| 45 | RSSIscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#RSSI. int `json:"rssi"` |
| 46 | Connectablescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Connectable. bool `json:"connectable"` |
| 47 | Flagsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Flags. string `json:"flags"` |
| 48 | Servicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Services. []BLEServicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService# `json:"services"` |
| 49 | } |
| 50 | |
| 51 | func NewBLEDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NewBLEDevice().(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#, a *gattscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/.Advertisementscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Advertisement#, rssi int) *BLEDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice# { |
| 52 | vendor := ManufLookupscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/ManufLookup().(NormalizeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NormalizeMac().(p.IDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Peripheral#ID().())) |
| 53 | if vendor == "" && a != nil { |
| 54 | vendor = a.Companyscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Advertisement#Company. |
| 55 | } |
| 56 | return &BLEDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#{ |
| 57 | LastSeenscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#LastSeen.: timescip-go gomod github.com/golang/go/src go1.16 time/.Nowscip-go gomod github.com/golang/go/src go1.16 time/Now().(), |
| 58 | Devicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Device.: p, |
| 59 | Vendorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Vendor.: vendor, |
| 60 | Advertisementscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Advertisement.: a, |
| 61 | RSSIscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#RSSI.: rssi, |
| 62 | Servicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Services.: make([]BLEServicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEService#, 0), |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func (d *BLEDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#) Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Name().() string { |
| 67 | // get the name if it's being set during services enumeration via 'Device Name' |
| 68 | name := d.DeviceNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#DeviceName. |
| 69 | if name == "" { |
| 70 | // get the name from the device |
| 71 | name = d.Devicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Device..Namescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Peripheral#Name().() |
| 72 | if name == "" && d.Advertisementscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Advertisement. != nil { |
| 73 | // get the name from the advertisement data |
| 74 | name = d.Advertisementscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Advertisement..LocalNamescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Advertisement#LocalName. |
| 75 | } |
| 76 | } |
| 77 | return name |
| 78 | } |
| 79 | |
| 80 | func (d *BLEDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#) MarshalJSONscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#MarshalJSON().() ([]byte, error) { |
| 81 | doc := bleDeviceJSONscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#{ |
| 82 | LastSeenscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#LastSeen.: d.LastSeenscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#LastSeen., |
| 83 | Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Name.: d.Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Name().(), |
| 84 | MACscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#MAC.: d.Devicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Device..IDscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Peripheral#ID().(), |
| 85 | Aliasscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Alias.: d.Aliasscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Alias., |
| 86 | Vendorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Vendor.: d.Vendorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Vendor., |
| 87 | RSSIscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#RSSI.: d.RSSIscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#RSSI., |
| 88 | Connectablescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Connectable.: d.Advertisementscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Advertisement..Connectablescip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Advertisement#Connectable., |
| 89 | Flagsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Flags.: d.Advertisementscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Advertisement..Flagsscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Advertisement#Flags..Stringscip-go gomod github.com/bettercap/gatt ec4935e8c4a0 `github.com/bettercap/gatt`/Flags#String().(), |
| 90 | Servicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/bleDeviceJSON#Services.: d.Servicesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/BLEDevice#Services., |
| 91 | } |
| 92 | return jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Marshal().(doc) |
| 93 | } |