-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_engagement.go
108 lines (91 loc) · 3.03 KB
/
device_engagement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package mdoc
import (
"errors"
"github.com/fxamacker/cbor/v2"
)
var (
ErrUnrecognisedRetrievalMethod = errors.New("mdoc: unrecognized retrieval method")
)
type DeviceEngagement struct {
Version string `cbor:"0,keyasint"`
Security Security `cbor:"1,keyasint"`
DeviceRetrievalMethods []DeviceRetrievalMethod `cbor:"2,keyasint,omitempty"`
ServerRetrievalMethods []any `cbor:"3,keyasint,omitempty"` // TODO
ProtocolInfo any `cbor:"4,keyasint,omitempty"` // TODO
}
func NewDeviceEngagementBLE(EDeviceKey *DeviceKey, centralClientUUID, peripheralServerUUID *UUID) (*DeviceEngagement, error) {
var eDeviceKeyBytes *TaggedEncodedCBOR
{
eDeviceKeyBytesUntagged, err := cbor.Marshal(EDeviceKey)
if err != nil {
return nil, err
}
eDeviceKeyBytes, err = NewTaggedEncodedCBOR(eDeviceKeyBytesUntagged)
if err != nil {
return nil, err
}
}
return &DeviceEngagement{
"1.0",
Security{
CipherSuiteIdentifier: CipherSuiteVersion,
EDeviceKeyBytes: *eDeviceKeyBytes,
},
[]DeviceRetrievalMethod{
{
Type: DeviceRetrievalMethodTypeBLE,
Version: 1,
RetrievalOptions: BLEOptions{
SupportsCentralClient: centralClientUUID != nil,
CentralClientUUID: centralClientUUID,
SupportsPeripheralServer: peripheralServerUUID != nil,
PeripheralServerUUID: peripheralServerUUID,
},
},
},
nil,
nil,
}, nil
}
func (de *DeviceEngagement) EDeviceKey() (*DeviceKey, error) {
eDeviceKey := new(DeviceKey)
if err := cbor.Unmarshal(de.Security.EDeviceKeyBytes.UntaggedValue, eDeviceKey); err != nil {
return nil, err
}
return eDeviceKey, nil
}
type Security struct {
_ struct{} `cbor:",toarray"`
CipherSuiteIdentifier int
EDeviceKeyBytes TaggedEncodedCBOR
}
type DeviceRetrievalMethodType uint
const (
DeviceRetrievalMethodTypeNFC DeviceRetrievalMethodType = 1
DeviceRetrievalMethodTypeBLE DeviceRetrievalMethodType = 2
DeviceRetrievalMethodTypeWiFiAware DeviceRetrievalMethodType = 3
)
type DeviceRetrievalMethod struct {
Type DeviceRetrievalMethodType
Version uint
RetrievalOptions RetrievalOptions
}
type RetrievalOptions any
type WifiOptions struct {
PassPhraseInfoPassPhrase string `cbor:"0,keyasint,omitempty"`
ChannelInfoOperatingClass uint `cbor:"1,keyasint,omitempty"`
ChannelInfoChannelNumber uint `cbor:"2,keyasint,omitempty"`
BandInfoSupportedBands []byte `cbor:"3,keyasint,omitempty"`
}
type BLEAddress [6]byte
type BLEOptions struct {
SupportsPeripheralServer bool `cbor:"0,keyasint"`
SupportsCentralClient bool `cbor:"1,keyasint"`
PeripheralServerUUID *UUID `cbor:"10,keyasint,omitempty"`
CentralClientUUID *UUID `cbor:"11,keyasint,omitempty"`
PeripheralServerDeviceAddress *BLEAddress `cbor:"20,keyasint,omitempty"`
}
type NFCOptions struct {
MaxLengthCommandData uint `cbor:"0,keyasint"`
MaxLengthResponseData uint `cbor:"1,keyasint"`
}